Databindings - small values treated as 0s

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.

That has resolved the isssue.

Leave a comment