Popup Menu for wxComboBox Topic is solved

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
LorDBulA
Experienced Solver
Experienced Solver
Posts: 53
Joined: Tue Feb 14, 2006 9:20 pm

Popup Menu for wxComboBox

Post 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 );
    event.Skip();
}
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?
LorDBulA
Experienced Solver
Experienced Solver
Posts: 53
Joined: Tue Feb 14, 2006 9:20 pm

Post 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?
lowjoel
Part Of The Furniture
Part Of The Furniture
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post 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);
Joel
Post Reply