BindingSource changing data after PropertyChangedEvent

39 views Asked by At

I have some controls bound to a Windows.Forms.BindingSource. The bound data is a class which communicates with a database and implements the INotifyPropertyChanged-interface. I implemented it like this:

public class MyClass: INotifyPropertyChanged {

public String Bezeichnung 
{
    get => _row["bez"].ToString();
    set
    {
        if (value == null)
           _row["bez"] = DBNull.Value;
        else
           _row["bez"] = value;
        NotifyPropertyChanged();
     }
}

public event PropertyChangedEventHandler PropertyChanged;

protected void NotifyPropertyChanged([CallerMemberName] String name = "")
{
    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
...

Inside my form I have a ValueChanged-event for a third-party Combobox (Infragistics UltraCombo). This Combobox is e.g. bound to the property Bezeichnung. The weird thing now is, that when I change another property of the db-class inside the ValueChanged event, it raises the event again and sets the Combobox-value back to what it was before. So I cannot change the value of the Combo as its resets it every time.

private void Combo_ValueChanged(object sender, EventArgs e) 
{
   ... 
   dbclass.Otherproperty = 42.9; 
   // after changing this and raising the PropertyChangedEvent,
   // this function gets called again (the value of the combo is back to its init value)
}

I assume it has something to do with the raise of the PropertyChangedEvent inside my db-class as it somehow "commits" all data and the BindindSource is rebinding all pending data. Changing the binding to DataSourceUpdateMode.OnPropertyChanged doesnt work either.

0

There are 0 answers