Hi guys,
I'm writing some code where there is a wxTextCtrl, with the style wxTE_PROCESS_ENTER.
I associated the textCtrl to an event with BIND that works when the user changes the tc.
I wrote a function that does the following: when the user changes the wxTextCtrl manually,
a wxString takes the new value inserted by the user.
The function is activated correctly when the event "user changes the tc value and presses enter" happens, but the new value of the tc is an empty string..
How can I solve it?
thank you very much
How to "capture" a wxTextCtrl changed by the user? Topic is solved
Re: How to "capture" a wxTextCtrl changed by the user?
You should be always able to obtain the content of wxTextCtrl using its GetValue() method.
In your event handler, you should be able to obtain the wxTextCtrl from which the event came from like this
In your event handler, you should be able to obtain the wxTextCtrl from which the event came from like this
Code: Select all
#include <wx/wx.h>
#include <wx/textctrl.h>
class MyDialog : public wxDialog
{
public:
MyDialog() : wxDialog(NULL, wxID_ANY, _("Test"), wxDefaultPosition, wxSize(800, 600))
{
wxTextCtrl* editCtrl = new wxTextCtrl(this, wxID_ANY, "Change me and press <Enter>",
wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
editCtrl->Bind(wxEVT_TEXT_ENTER, &MyDialog::OnTextEnter, this);
}
private:
void OnTextEnter(wxCommandEvent& event)
{
wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>(event.GetEventObject());
if ( textCtrl )
wxLogMessage("OnTextEnter(): %s", textCtrl->GetValue());
}
};
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
MyDialog().ShowModal();
return false;
}
}; wxIMPLEMENT_APP(MyApp);
Re: How to "capture" a wxTextCtrl changed by the user?
oooh thank you very much...I tried using GetLabel() and GetLabelText but these 2 didn't give me the expected value.
I will try with your method! Thanks again!
I will try with your method! Thanks again!