Solved

one event handlers for multiple actions

Posted on 2006-06-14
6
322 Views
Last Modified: 2010-04-16
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.
0
Comment
Question by:yanci1179
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 16902786
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)
        {

        }
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 16902797
Just make them all point to the same method...

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

    private void Any_TextChanged(object sender, EventArgs e)
    {
        button1.Enabled = true;
    }
0
 

Author Comment

by:yanci1179
ID: 16902918
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.

0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 28

Expert Comment

by:2266180
ID: 16903391
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.
0
 

Author Comment

by:yanci1179
ID: 16903632
0
 
LVL 28

Expert Comment

by:2266180
ID: 16904046
I just got home. I'll take a look at it in half an hour or so if nobody gets to it.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question