NumericUpDown

  • Thread starter Thread starter Peter Morris
  • Start date Start date
P

Peter Morris

I need to change the behaviour of NumericUpDown (compact framework 2.0) so
that I can show a dialog stating that the value is not within the allowed
range rather than just capping the input value. Any ideas how I can achieve
this? I don't seem able to find a suitable place to hook into (pre
set-value).


Thanks


Pete
 
Not sure if I completely understand your question, but:

private void numericUpDown1_ValueChanged(object sender,
EventArgs e)
{
if (this.numericUpDown1.Value > 5)
{
MessageBox.Show("Value cannot be greater than 5");
this.numericUpDown1.Value = 5;
}
}

Seems to work fine for me.
 
That occurs after the value has changed, as a consequence the property on
the object it is bound to has already been set and thrown an out of range
exception. I need something which occurs before the value is set. The
Validating event is not executed though.
 
I think I have solved it, it was quite a complicated process. I will blog
about it at some point and post the solution here.


Pete
 
Any recommendations on preventing the loss of focus rather than forcing
focus back when the value is invalid?
 
Back
Top