Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2005, 06:41 AM
Registered User
 
Join Date: Mar 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default setting event handled to true

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
 
Old April 27th, 2005, 10:51 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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
 
Old April 27th, 2005, 11:14 AM
Authorized User
 
Join Date: May 2004
Posts: 83
Thanks: 0
Thanked 1 Time in 1 Post
Default

Dear Sajid,

To avoid firing the said event unwantedly, you can use a boolean field in your class (derived from Form).

Code:
//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
 
Old April 27th, 2005, 12:02 PM
Registered User
 
Join Date: Mar 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting onChange Event w/Dynamically Created Form rvanandel Javascript How-To 4 June 28th, 2007 08:10 AM
How to suspend code till Activex event is handled fossx VB How-To 1 June 1st, 2007 10:57 AM
fired event Sorting which wasn't handled fantef ASP.NET 2.0 Basics 0 July 27th, 2006 10:05 AM
setting both onclick and ondblclick event handlers oranginalab Javascript How-To 3 November 25th, 2004 03:50 PM
Setting oncheckedchanged event in code behind file katsarosj VS.NET 2002/2003 4 May 12th, 2004 12:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.