Vincenzo Lo Palo
Vincenzo Lo Palo

Reputation: 1381

Simultaneously update two textbox in C#

When I insert data in textbox1, I need that in textbox2 is placed same data simultaneously.

I dont know which event permits this feature. Im using visual studio 2010.

thanks in advance!

Upvotes: 0

Views: 830

Answers (2)

mishmash
mishmash

Reputation: 4458

Use the TextChanged event on textbox1 and use it to update textbox2:

// This can be done via designer too.
this.textbox1.TextChanged += new EventHandler(textbox1_TextChanged);

Now, in your form class:

void textBox1_TextChanged(object sender, EventArgs e)
{
    textbox2.Text = textbox1.Text;
}

Hope this helps.

Upvotes: 4

e_ne
e_ne

Reputation: 8459

Add this handler to the TextChanged event of textBox1:

private void OnTextChanged(object sender, EventArgs e)
{
    var textBox = sender as TextBox;
    textBox2.Text = textBox.Text;
}

Upvotes: 0

Related Questions