Page 1 of 1

Popup Menu for wxComboBox

Posted: Tue Jun 19, 2007 6:45 pm
by LorDBulA
Hello I want to Popup menu when right mouse button is clicked on ComboBox.

This is my code:

Creating controls and Connecting to mouse event.

Code: Select all

ComboControl = new wxComboBox(MainPanel, ID_COMBOCONTROL, wxT(""), wxPoint(10,20), wxSize(200,21), arrayStringFor_ComboControl, wxCB_READONLY, wxDefaultValidator, wxT("ComboControl"));

ComboMenu = new wxMenu(wxT(""));ComboMenu->Append(ID_MNU_RENAME_1010, wxT("Rename"), wxT(""), wxITEM_NORMAL);
	ComboMenu->Append(ID_MNU_DELETE_1009, wxT("Delete"), wxT(""), wxITEM_NORMAL);

ComboControl->Connect(wxID_ANY ,wxEVT_RIGHT_UP,wxMouseEventHandler( MercPoolDialog::ComboRightUp )  );

Poping up menu.

Code: Select all

void MercPoolDialog::ComboRightUp( wxMouseEvent& event ){
    ComboControl->PopupMenu( ComboMenu );
When I right click combo applicatoion crashes.
Is it posible to make popup manu for combo box?
If so then could You give me any pointers how to do it correctly?

Posted: Tue Jun 19, 2007 7:56 pm
by LorDBulA
I deriverd wxComboBox and made wxComboBoxWithMenu and I got it to work.

But I would still like to know why It doesnt work with Connect?

I also checked wxTimer and I got the same result (crash) when I start Timer from inside Connect ( Exactly the same code as above).
Calling other functions that change other controls in my dialog also ends in the same way.

Did I use Connect in wrong way?

Posted: Mon Jul 02, 2007 2:13 am
by lowjoel
Yes, You are using the wrong this pointer to call your function.

You should write:

Code: Select all

ComboControl->Connect(wxID_ANY ,wxEVT_RIGHT_UP,wxMouseEventHandler( MercPoolDialog::ComboRightUp )  , NULL, this);