2

I'm binding a decimal (from an NHibernate entity) to a NumericUpDown.

_numUpDown.DataBindings.Add(
    New Binding(
        "Value", 
        _BindingSource, 
        "TheDecimal", 
        False, 
        DataSourceUpdateMode.OnPropertyChanged
    )
)

This works fine. However when I change the minimum value on the NumericUpDown from 0 to .01 I get an error.

From the designer;

Me._numUpDown.Minimum = New Decimal(New Integer() {1, 0, 0, 131072})

The error;

1) System.InvalidOperationException 
---------------------------------------
Message: DataBinding cannot find a row in the list that is suitable for all bindings.
Target: Void FindGoodRow()
Source: System.Windows.Forms

What can I do to get it to bind when the minimum value isn't 0?

mortiped
  • 869
  • 1
  • 6
  • 28
Fenyx4
  • 152
  • 6

1 Answers1

0

Based on https://stackoverflow.com/a/10908342/429091, try changing the formattingEnabled parameter (that fourth parameter you have set to False) to be True. This seems to cause .net winforms to ignore the incompatibility between the default decimal value of 0m and your NumericUpDown.Minimum.

With this change, it should appear that the NumericUpDown is ignoring any incompatible data and just leaving its Value property unmodified in all the cases where you used to get this InvalidOperationException. I do not know why this is the case. Maybe the documentation of Binding.FormattingEnabled explains it in this excerpt:

Setting this property to true also enables error-handling behavior and causes the BindingComplete event to be raised. The handler of this event can take the appropriate action, based on the success, error, or exceptions in the binding process, by examining the BindingCompleteState property of the BindingCompleteEventArgs parameter.

That might mean that if you wanted to make the binding fail in this case when formatting is enabled, you’d have to implement that event. I’m not sure how useful this would be. Maybe you would want to notify the user that the value displayed in the NumericUpDown does not reflect any data-bound item at the moment (either because the selected item in the list has a value below the Minimum or because there is no item currently in the list because it hasn’t been populated yet or there just aren’t any items).

Community
  • 1
  • 1
binki
  • 7,754
  • 5
  • 64
  • 110