ValueChanged event

J

joe

Hi,

I have a numeric up-down control.
1. How can I distinguish between programatic value change
(like MyControl.Value=25) and user interface change
(clicking the arrows)?
2. If the numeric up-down has some value in it (lets say
27), if we select the text and type 27 again, ValueChanged
event will not be fired (I assume becose it is equal to
the old value). Is there a way to change this behaviour so
that the control fires the event even if the new value is
equal to the old one?

Thank you
 
C

ClayB [Syncfusion]

1) I think you can test Control.MouseButtons to decide whether the value
changed because of a click or not.

private void numericUpDown1_ValueChanged(object sender, System.EventArgs e)
{
if(Control.MouseButtons == MouseButtons.Left)
{
Console.WriteLine("numericUpDown1_ValueChanged");
}
}

2) Maybe using the numericUpDown1_TextChanged event will allow you the
catch these actions.

====================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
C

Christoph Nahr

2. If the numeric up-down has some value in it (lets say
27), if we select the text and type 27 again, ValueChanged
event will not be fired (I assume becose it is equal to
the old value). Is there a way to change this behaviour so
that the control fires the event even if the new value is
equal to the old one?

ValueChanged doesn't even fire if the typed value is different from
the old one. That's a .NET Framework bug since version 1.0.

You'd have to use TextChanged but then you'd get an event for "2" and
then another one for "27" in your example, so that's not ideal either.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top