Solved

one event handlers for multiple actions

Posted on 2006-06-14
6
317 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:ciuly
Comment Utility
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
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 28

Expert Comment

by:ciuly
Comment Utility
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
Comment Utility
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

772 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

10 Experts available now in Live!

Get 1:1 Help Now