dynamic event - wxListCtrl please help

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
JumpAround
In need of some credit
In need of some credit
Posts: 5
Joined: Fri Feb 04, 2005 8:15 am

dynamic event - wxListCtrl please help

Post by JumpAround » Fri May 12, 2006 4:09 pm

Hi all

I have wxListCtrl *listCtrl; variable declared in my Dialog class. Everything works fine but I want to dynamicly connect an event handler ( selection an item ) to this listCtrl.
I have no idea how to accomplish that. I saw the examples but I cannot find any event which will be suitable in my case. Is anyone who knows how to do it? I don't want to derive my ctrl from the wxListCtrl class.

Please help

toxicBunny
Super wx Problem Solver
Super wx Problem Solver
Posts: 424
Joined: Tue Jul 12, 2005 8:44 pm
Location: Alabama, USA

Post by toxicBunny » Fri May 12, 2006 5:51 pm

Try this to add a handler for a specific event type:

Code: Select all

myListCtrl->Connect( wxID_ANY, Some_Event_Type, wxListEventHandler( MyParent::OnKeyDown ), NULL, Pointer_To_MyParent );
where myListCtrl is a pointer to the list control, Some_Event_Type would be replaced by the type of event you would like to handle (EVT_LIST_ITEM_SELECTED, EVT_LIST_ITEM_DESELECTED, etc...),

http://www.wxwidgets.org/manuals/2.6.3/ ... xlistevent

MyParent would be the name of the class in which you want to handle the event, and Pointer_To_MyParent is a pointer to the class. Then create an event handler function in the MyParent class like this:

Code: Select all

void HandleListEvent( wxListEvent& event )
Something that is a bit simpler may be to use wxWindow::SetEventHandler

http://www.wxwidgets.org/manuals/2.6.3/ ... enthandler

or wxWindow::PushEventHandler

http://www.wxwidgets.org/manuals/2.6.3/ ... enthandler

to simply set an event handler for the list control, which would handle all events for it.

-Scott
wxMSW 2.6.2, VS 2002, 2003 and 2005, Code::Blocks and mingw, Windows XP Pro

Post Reply