Solved

one event handlers for multiple actions

Posted on 2006-06-14
6
318 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
  • 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 85

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now