i would want to set a variable to either true or false whenever i change a text field.
how do i do this?
TextField Change Topic is solved
Re: TextField Change
You Bind/Connect a wxEVT_COMMAND_TEXT_UPDATED event of wxTextCtrl(s) you're interested in.
By the way, are you aware that there is actually a decent official documentation for wxWidgets and a lot of code samples in wxWidgets's samples directory?
By the way, are you aware that there is actually a decent official documentation for wxWidgets and a lot of code samples in wxWidgets's samples directory?
Re: TextField Change
I am aware thanks samples are a bit complicated for me. I am still learning the basics.
- xaviou
- Super wx Problem Solver
- Posts: 437
- Joined: Mon Aug 21, 2006 3:18 pm
- Location: Annecy - France
- Contact:
Re: TextField Change
Hi
You probably don't need a variable to do this : just check if your wxTextCtrl has been marked as modified :
Regards
Xav'
You probably don't need a variable to do this : just check if your wxTextCtrl has been marked as modified :
Code: Select all
if (the_wxTextCtrl->IsModified())
{
DoSomethingOrNot();
}
Xav'
My wxWidgets stuff web page : X@v's wxStuff
Re: TextField Change
While xaviou's example works, if you need to be notified every time the value in the edit control(s) changes, you need to do something like this:
If you're for some reason still using wxWidgets 2.8, replace line starting with "textCtrl->Bind" with
Code: Select all
#include <wx/wx.h>
class MyFrame : public wxFrame
{
public:
MyFrame()
: wxFrame(NULL, wxID_ANY, _("Test"))
{
wxBoxSizer* bSizer = new wxBoxSizer(wxVERTICAL);
wxTextCtrl* textCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
bSizer->Add(textCtrl, 1, wxEXPAND);
SetSizer(bSizer);
textCtrl->Bind(wxEVT_COMMAND_TEXT_UPDATED, &MyFrame::OnTextUpdated, this);
m_modified = false;
}
private:
bool m_modified;
void OnTextUpdated(wxCommandEvent& event)
{
// if you need to get wxTextCtrl* that initiated the event, you can do:
// wxTextCtrl* textCtrl = dynamic_cast<wxTextCtrl*>(event.GetEventObject());
if ( !m_modified ) {
m_modified = true;
SetTitle(GetTitle().Append(wxS(" *")));
// you need to set m_modified to false and remove the " *" from the title after saving a document etc.
}
}
};
class MyApp : public wxApp
{
public:
virtual bool OnInit()
{
if (!wxApp::OnInit())
return false;
MyFrame* frame = new MyFrame();
frame ->Show();
return true;
}
};
IMPLEMENT_APP(MyApp)
Code: Select all
textCtrl->Connect(wxEVT_COMMAND_TEXT_UPDATED, wxCommandEventHandler(MyFrame::OnTextUpdated), NULL, this);
Re: TextField Change
Thank for all the help I greatly appreciate it.