Search code examples
c++eventswxwidgets

How to call an programmatically generated event for wxRadioButton in wxWidgets?


I am trying to programmatically change a value of a wxRadioButton in a way the user would do it. A value change doesn't call the event corresponded to the button, and it make sense since the documentation says it clearly:

wxRadioButton::SetValue
void SetValue(const bool value)
Sets the radio button to selected or deselected status.
This does not cause a wxEVT_COMMAND_RADIOBUTTON_SELECTED event to get emitted.

So the question is how can I call an programmatically generated event for a wxRadioButton ?

I guess that it's something to do with:

wxWindow window->AddPendingEvent(wxEvent *event )

A simple example would be greatly appreciated.


Solution

  • You can use AddPendingEvent or ProcessEvent (handle immediately).

     bttn->SetValue(true);
     wxCommandEvent ev(wxEVT_COMMAND_RADIOBUTTON_SELECTED, id_button);
     bttn->GetEventHandler()->ProcessEvent(ev);
    

    It should also be possible to use wxControl::Command, but it seems to me that SetValue should be called after that(?).