Solved

one event handlers for multiple actions

Posted on 2006-06-14
6
319 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

785 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