I have numericUpDown control minValue - 0 maxValue - 100.
I create binding to this control.
If the value changes to 101 will be the exception, which I do not need, and I would like to value is not specifically mentioned. how to do it ?
UPDATE:
BindinHelper.BindField(this.nUpDownExecArea, "Value", TempConfigClass, "ExecArea");
BindField:
public static void BindField(Control control, string propertyName,
object dataSource, string dataMember)
{
Binding bd;
for (int index = control.DataBindings.Count - 1; (index == 0); index--)
{
bd = control.DataBindings[index];
if (bd.PropertyName == propertyName)
control.DataBindings.Remove(bd);
}
control.DataBindings.Add(prope开发者_如何学PythonrtyName, dataSource, dataMember, false, DataSourceUpdateMode.OnPropertyChanged);
}
I set TempConfigClass.ExecArea = 99999;
does not result in errors, but when I go to a tab (tabcontrol) where the error appears to be numericUpDown
An argumentOutOfRangeException is telling you that the argument received was exceptional. However if your app is designed in a way to expect certain arguments there are two ways to go about it:
The recommended way - Simply check the value prior to the binding taking place and prevent it going any further if out of range
or - Use a try/catch block to catch the specific exception only and deal with it accordingly
精彩评论