0

I have a NumericUpDown control, which is a part of a UserControl. The UserControl has Value property:

[Browsable(true)]
public override double Value
{
    get { return this.ControlValue; }
    set
    {
        this.ControlValue = value;
        InvokePropertyChanged(new PropertyChangedEventArgs("Value"));
    }
}

I used DataBindings for the NumericUpDown:

NumericUpDown.DataBindings.Add(nameof(NumericUpDown.Value), this, nameof(UserControl.Value), false, DataSourceUpdateMode.OnPropertyChanged);

The Value property used to be Int32, but I had to change it to Double. And suddenly the binding stopped working.

I know for sure the Value property is changing, but the NumericUpDown's value doesn't.

Correction: it appears the Binding only fails to update NumericUpDown's value when the Value property is changed. Changing NumericUpDown's value DOES change the Value property.

YosiFZ
  • 7,792
  • 21
  • 114
  • 221
Technical
  • 145
  • 1
  • 11

1 Answers1

0

So, the problem actually was not in the Binding or the NumericUpDown control, but rather in the "override" keyword. In this case, the binding was confused which property was changing - UserControl's Value or its base class. This was solved by using "new" instead of "override".

Still can't understand why I didn't have this problem earlier. This code is 4-5 months old and worked perfectly before I changed Value property type from Int32 to Double.

Technical
  • 145
  • 1
  • 11
  • Maybe answer https://stackoverflow.com/questions/1399127/difference-between-new-and-override can shed some light onto the result. – Markus Deibel Mar 12 '19 at 10:41