Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextChanged Event of NumericUpDown

I am using Microsoft Visual C# 2010 Express. When i change the value of numericUpDown using arrows, my button becomes enable. But i also want to enable my button when i change the value of numericUpDown by changing the text directly.

I am using the following code:

private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
    button1.Enabled = true;
}
like image 367
Lany Avatar asked Jul 09 '13 07:07

Lany


1 Answers

You may need to use TextChanged event instead of using ValueChanged. The Value changed event need you to press enter key after changing value to get ValueChanged fired.

What MSDN say about NumericUpDown.ValueChanged Event

For the ValueChanged event to occur, the Value property can be changed in code, by clicking the up or down button, or by the user entering a new value that is read by the control. The new value is read when the user hits the ENTER key or navigates away from the control. If the user enters a new value and then clicks the up or down button, the ValueChanged event will occur twice, MSDN.

Binding TextChanged event.

private void TestForm_Load(object sender, EventArgs e)
{
    numericUpDown1.TextChanged += new EventHandler(numericUpDown1_TextChanged);
}

Declaration of TextChanged event.

void numericUpDown1_TextChanged(object sender, EventArgs e)
{
    button1.Enabled = true;
}
like image 162
Adil Avatar answered Oct 08 '22 10:10

Adil