Search code examples
wxwidgets

Distinguish between clicks on two wxWidgets Property Grid buttons


I can write

 wxPropertyGrid * pg;

 ...

 wxStringProperty * pA = new wxStringProperty("A",
                                      wxPG_LABEL,"");
 wxStringProperty * pB = new wxStringProperty("B",
                                      wxPG_LABEL,"");
 pg->Append( pA );
 pg->Append( pB ); 
 pg->SetPropertyEditor( pA, wxPGEditor_TextCtrlAndButton );
 pg->SetPropertyEditor( pB, wxPGEditor_TextCtrlAndButton );
 Bind( wxEVT_COMMAND_BUTTON_CLICKED,
       &cFrame::OnPropertyButton, this );

...

void cFrame::OnPropertyButton( wxCommandEvent& event )
{
   wxMessageBox(wxString::Format("button %d", event.GetId()));
}

and it works, quite well - the button message pops up when I click on the button in either property A or B

But, how do I distinguish, in the event handler, between clicks on A and B.

Normally, I would get the button id from the event, but these buttons do not appear to have IDs - the message shows the same ID for both.


Solution

  • I found that I can grab the label from the currently active property, and so use that to make the distinction

    void cFrame::OnPropertyButton( wxCommandEvent& event )
    {
        wxMessageBox(wxString::Format("button %s",
                                  pg->GetSelection()->GetLabel()));
    }