-
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
-
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
-
Re: Textbox Event
@popskie:
thanks - I will try it
-
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
-
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