|
Subject:
|
setting event handled to true
|
|
Posted By:
|
sajid
|
Post Date:
|
4/27/2005 6:41:16 AM
|
hi
i have a textbox and a text_changed event attached to it.
in the text_changed event, i need to change the text which again
triggers this event and hence this goes in infinite loop.
Does anybody know if there is any property that can be set to true
so that it doesn't fire the event again and again.
Thx
|
|
Reply By:
|
planoie
|
Reply Date:
|
4/27/2005 10:51:35 AM
|
I don't believe such a thing exists because that would break the whole event model. If you change the text, the event get's fired regardless of what changes the text.
You could certainly write in some kind of check to filter out certain passes thru the handler based on your specific criteria.
-Peter
|
|
Reply By:
|
ejan
|
Reply Date:
|
4/27/2005 11:14:03 AM
|
Dear Sajid,
To avoid firing the said event unwantedly, you can use a boolean field in your class (derived from Form).
//field declaration
boolean eventFired = false;
//Now in the event handler
if (!eventFired) {
//set the field to true so this event handler will
//return as soon as called afterwards
eventFired = true;
//do your processing...
//change the text which will again fire this event
//but since the value of the eventFired field will
//be true, as soon as this event is fired the second
//time, it will return without doing anything
//now after doing all processing needed, reset the
//eventFired field, so future events are processed
eventFired = false;
}
I hope this helps.
Regards,
ejan
|
|
Reply By:
|
sajid
|
Reply Date:
|
4/27/2005 12:02:42 PM
|
thx for answers both of u ..
ejan, this was the only thing i cud think of ... but i was looking for a shortcut like in KEYPRESS event, therez a property "handled" which we can set to true or false accordingly, i think.
|