I have an application that has a number of UpDown boxes for setting values of a configuration file before loading the file onto an embedded device. I can load a configuration from the device and display the values in the appropriate UpDown boxes.
However, if I delete the contents of an UpDown box and then update it's value, the value of the updown box does not get redrawn unless I increment or decrement the value with the integrated buttons.
Steps to take to reproduce:
I have tried the following with no change.:
fenceNumberUpDown.Value = config.getFenceNumber();
fenceNumberUpDown.Refresh();
fenceNumberUpDown.Update();
fenceNumberUpDown.ResetText();
fenceNumberUpDown.Select();
fenceNumberUpDown.Hide();
fenceNumberUpDown.Show();
fenceNumberUpDown.Invalidate();
Here's a couple of workarounds I was able to come up with or may give you some other ideas to solve the problem.
Workaround #1: Call UpButton() before setting the value.
this.numericUpDown1.UpButton();
this.numericUpDown1.Value = 20;
Workaround #2: Extend NumericUpDown and overide the Value property.
public class NumericUpDownNew : NumericUpDown
{
public new decimal Value
{
get { return base.Value; }
set
{
string text = "";
if(this.ThousandsSeparator)
text = ((decimal)value).ToString("n" + this.DecimalPlaces);
else
text = ((decimal)value).ToString("g" + this.DecimalPlaces);
Controls[1].Text = text;
base.Value = value;
}
}
}