wxRearrangeCtrl: Howto catch select event

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
vanarieleyen
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Aug 29, 2019 3:55 am

wxRearrangeCtrl: Howto catch select event

Post by vanarieleyen » Sat Aug 31, 2019 8:02 am

I am stuck with a simple problem...

I have a wxRearrangeCtrl and would like to perform some additional action when I click on a list item.

Here is some code:

const long MY_ID = wxNewId();

wxRearrangeCtrl * arrange = new wxRearrangeCtrl(parent, MY_ID, pos, size, order, items, style, validator, name);

Connect(MY_ID, wxEVT_COMMAND_LISTBOX_SELECTED, (wxObjectEventFunction)&OnSelectClick);

void OnSelectClick(wxCommandEvent& event) {
wxMessageBox("OK");
}

The arrangebox is working well. It is shown and I can arrange the items.
However when I select an item I would like to perform some extra code but the event is never fired.

I guessed I had to subclass wxRearrangeCtrl which I did, but how to go further?

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

Re: wxRearrangeCtrl: Howto catch select event

Post by doublemax » Sat Aug 31, 2019 10:11 am

The problem is that wxRearrangeCtrl is a composite control, it contains multiple other controls internally. And the ID "MY_ID" that you assign for the wxRearrangeCtrl, will not be used for the internal wxListBox. So, either use wxID_ANY for the ID in the Connect call, or retrieve the correct ID from the internal control using arrange->GetList()->GetId()
Use the source, Luke!

vanarieleyen
Earned a small fee
Earned a small fee
Posts: 15
Joined: Thu Aug 29, 2019 3:55 am

Re: wxRearrangeCtrl: Howto catch select event

Post by vanarieleyen » Wed Sep 04, 2019 12:56 am

Just to tell you that your suggestion worked :D

I also wanted to do this so I had already made a class that inherits from wxRearrangeCtrl but I didn't know how to get the id from the list. I searched the wx doc's but nowhere is GetId() mentioned...

Post Reply