Today, I encountered an interesting problem with WinForms. In the application, NumericUpDowns (shown below) were used with small values e.g. 0.00001 etc. However, after we refreshed the panel, the value was being set to the default value.
Digging further into the problem it turned out that the default Microsoft DataBinding converter was unable to convert values smaller than 0.0000. This resulted in the exception Input string was not in the required fromat. This caused the databinding to fail.
To resolve the issue, rather than set controlUpDown.DataBinding.Add(param1, param2, param3)
replace with the actual Binding
. Additionally, the Format
event had to be specified in order to enable conversion.
1 2 3 4 |
public void upDown_Format(object sender, ConverterArgs e) { if (e.DesiredType is float) e.Value = float.Parse(e.Value) } |
That has resolved the isssue.