KeyEvent on ListBox Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Lloyd
Super wx Problem Solver
Super wx Problem Solver
Posts: 350
Joined: Wed May 03, 2006 2:36 pm
Location: India
Contact:

KeyEvent on ListBox

Post by Lloyd » Fri Jun 20, 2008 5:08 am

Hi,

I have a wxListBox on a wxDialog Derived class. In the derived class' onstructor ListBox object is made and connected it with the event handler like this

Code: Select all

SearchDialog::SearchDialog(UserInterface* UserInterfaceptr,wxWindow* parent,wxWindowID id, const wxString& title,const wxPoint& pos,const wxSize& size):wxDialog(parent,id,title,pos,size)
{
....
....

SearchList=new wxListBox(this,ID_SEARCH_LISTBOX,wxDefaultPosition,wxSize(200,203),0,NULL,wxLB_EXTENDED|wxLB_NEEDED_SB|wxSUNKEN_BORDER);
  SearchList->Connect(ID_SEARCH_LISTBOX,wxEVT_CHAR,wxKeyEventHandler(SearchDialog::OnDel));

...
...
}
Then the OnDel function is defined like this

Code: Select all

void SearchDialog::OnDel(wxKeyEvent& event)
{
 ...

 if(SearchList->GetCount()==0)
    return; 
 ....
When the code reaches the GetCount() fn. the application crashes (Access Violation). (on Both Linux and Windows). What could be the reason?

Thanks,
Lloyd

User avatar
doublemax
Moderator
Moderator
Posts: 15159
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Fri Jun 20, 2008 9:24 am

another victim who fell into the event sink trap ;)

Use this as eventsink parameter in your connect() call and you're fine.

http://forums.wxwidgets.org/viewtopic.php?p=85170#85170
Use the source, Luke!

Lloyd
Super wx Problem Solver
Super wx Problem Solver
Posts: 350
Joined: Wed May 03, 2006 2:36 pm
Location: India
Contact:

Post by Lloyd » Fri Jun 20, 2008 10:20 am

Thans doubloe max. Now I understood the cause of problem.

Lloyd

Post Reply