Search code examples
c++wxwidgets

Calling an event handler after text has been modified in wxWidgets


I am trying to create a situation in my wxWidgets application where a user can type something into a text box, and if there are one or more characters in the text box, other controls become enabled. As such, I created an event handler that checks TextBox->IsEmpty() on the event wxEVT_COMMAND_TEXT_UPDATED. However, this seems to be called before the changes to the text in the text box take place. Is there any way to get an event to fire after the changes have occurred? Thank you.

EDIT: Code I am using. I am using Connect() to set up the event handling, so there is no event table to speak of. This is the code I am using:

cur->mTextBox = new wxTextCtrl(mParentFrame, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize);
mParentFrame->Connect(wxID_ANY, wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(iguiFrame::correctTextBoxes));

correctTextBoxes is a public method of my wxFrame derived class, which calls a function containing only the following code:

if(cur->mTextBox->IsEmpty())
{
    wxMessageBox("Empty!");
}

The message box always pops up "one character" too late.


Solution

  • As @ravenspoint mentioned, this event should have been fired after the change was made, but I also wanted to point out that even in the cases where an event is fired just before a change is made, the change is almost always passed into your event handler with the event parameter.

    So for this case, you may want to actually just check the value of event.GetString() in correctTextBoxes() to see the new value being set on the text control.