Link to home
Start Free TrialLog in
Avatar of yanci1179
yanci1179

asked on

one event handlers for multiple actions

I have 10 text boxes and what I would like to do is when one of them changes

to enable the save button.


Instead of having 10 diff event handlers for each text box is there a way that I can have one event handler that handles text change on all the textboxes?

I have:
this.TxFName.TextChanged +=new EventHandler(TxFName_TextChanged);
this.TxLName.TextChanged +=new EventHandler(TxLName_TextChanged);

    private void TxFName_TextChanged(object sender, EventArgs e)
        {

        }
 private void TxLName_TextChanged(object sender, EventArgs e)
        {

        }

I have this ten times.  There has to be an easier way.  Any ideas?

thanks.
Avatar of 2266180
2266180
Flag of United States of America image

do it directly from code, not the IDE. like:

this.TxFName.TextChanged +=new EventHandler(TxFName_TextChanged);
this.TxLName.TextChanged +=new EventHandler(TxFName_TextChanged);

    private void TxFName_TextChanged(object sender, EventArgs e)
        {

        }
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yanci1179
yanci1179

ASKER

thanks Idle_Mind.

Also, Do you know what is the best event to use.  I tried TextChanged and I guess since onload the focus is set to the textbox it assumes textchanged so it automatically enables the button.  I used Validated and that works okay when the user tabs to another control.

But it enables the button even if no text is changed, all it takes is to move to another control.  

Thanks for your help.

I gave the same solution as idle_mind and a few seconds faster. a split should have been the proper way to go on this.
nothing personal, but it happens too many times (this is the 3rd time in the last few weeks (cumulated with another ta); more or less the same situation)
what is done is done, just pay more attention next time.
peace.
I just got home. I'll take a look at it in half an hour or so if nobody gets to it.