|
-
Nov 15th, 2005, 01:24 AM
#1
Thread Starter
Hyperactive Member
Textbox Event
Greetings, I have a form with 20 Textboxes. When the user leaves the textbox and has changed anything an update has to be written to the DB.
Is it possible to use only one Eventhandler to cover all Textboxes or do I realy need for every Textbox on this form an own Eventhandler?
Thankx in advance
-
Nov 15th, 2005, 01:37 AM
#2
Fanatic Member
Re: Textbox Event
hi,
In my exp. yes u can.
in any event you put this code. Instead of using each textbox name.
((TextBox)sender).Text
-
Nov 15th, 2005, 01:42 AM
#3
Thread Starter
Hyperactive Member
Re: Textbox Event
@popskie:
thanks - I will try it
-
Nov 15th, 2005, 03:05 AM
#4
Re: Textbox Event
You can make the method work for different controls by clicking the events button on the form designer properties, and choosing the method from the drop down list.
note, that, If you look under "Windows Form Designer code" you will see the IDE adds the handler by using this method:
Code:
this.textBox3.Validating += new System.ComponentModel.CancelEventHandler(this.multivalidator);
Which you could also use yourself programatically at runtime to add event handlers.
Bill
-
Nov 15th, 2005, 10:13 AM
#5
Re: Textbox Event
In the designer code, set all of them to have the same event handler, like this for example:
PHP Code:
this.textBox1.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
this.textBox3.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
Then you can have a look in the event:
PHP Code:
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
TextBox txtTemp = (TextBox)sender;
MessageBox.Show(txtTemp.Name + " has changed!");
}
HTH
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|