Can the EVT_TEXT event be prevented on call to SetLabel()?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

Can the EVT_TEXT event be prevented on call to SetLabel()?

Post by spflanze »

Is there a way to get the EVT_TEXT event to trigger when a user enters a text into a wxTextCtrl object and not when wxTextCtrl ::SetLabel() is called?

The goal is for the text color to be red until the user has used the enter key at which point I need it black to show feedback the text is entered. I have accomplished this by changing it to red whenever EVT_TEXT is triggered, and black when TE_PROCESS_ENTER is triggered using wxTextCtrl ::SetForegroundColour(). But this goes wrong when I need to put put text in that same control from a database, and have that text appear in black. This this is not happening because when I call wxTextCtrl ::SetLabel() to set that text the EVT_TEXT is triggered and so the text turns red.

It did not work to call wxTextCtrl ::SetForegroundColour() after wxTextCtrl ::SetLabel().
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Can the EVT_TEXT event be prevented on call to SetLabel()?

Post by PB »

I may be missing something as you refer to SetLabel(), but if you want to change the value of wxTextCtrl without triggering text event, call its ChangeValue():http://docs.wxwidgets.org/trunk/classwx ... 8e763cbca1
User avatar
saifcoder
Experienced Solver
Experienced Solver
Posts: 80
Joined: Thu Nov 16, 2017 9:32 pm

Re: Can the EVT_TEXT event be prevented on call to SetLabel()?

Post by saifcoder »

wxTextEntry::ChangeValue()
This functions does not generate the wxEVT_TEXT event but otherwise is identical to SetValue().
If you find a difficulty.. tray use "Crooked ways" !

Code: Select all

bool IGN_EVENT = false
...
foo(){
	IGN_EVENT = true
	SetLabel()..
}

OnChange(){
	if (IGN_EVENT) return;
}
Debian 9 - GCC 6 - wxWidgets 3.x U
Win 10 - GCC 8 - wxWidgets 3.x U
Mac OS X 10.x - Clang - wxWidgets 3.x U
i am in love with WX. Yes.
Post Reply