Thursday, May 5, 2011

Editing a DataGridView which has bound and updating columns in C#

I have a DataGridView where the DataSource is a BindingList. Most of the columns are updated -- via various timers which call PropertyChanged("...") for the bound columns. One column -- the problematic one -- is a DataGridViewComboBoxColumn -- where the user selects an item from the list of Items.

The problem is that the DataGridViewComboBoxColumn is not usable. It is flashing all the time -- apparently when PropertyChanged events occur -- and whatever item I try to select, it remains unchanged.

Any idea what I'm doing wrong?

From stackoverflow
  • First of all, add code sample so we can better understand what you mean.

    Second, what you do sounds weird. Why do you call PropertyChanged() manually on timer? Why don't you implement INotifyPropertyChanged in your class?

    Or you could use a wrapper, implementing ICustomTypeDescriptor and INotifyPropertyChanged for your items. In this case, the wrapper will add INotifyPropertyChanged implementation for your classes automatically. Search internet for information on why do you need ICustomTypeDescriptor and how it can help.

    Joe H : Well, I admit that what I'm doing is a little weird. I do implement INotifyPropertyChanged in my class. The class also has a timer to call PropertyChanged for some elements which change very often (many times per second) for performance reasons (based on profile results). As far as code samples, it is from a large complex codebase. I will try though.
  • One issue you might have is that the DataGridViewComboBox control does not commit it's value change until the cell is validated by the user moving to another cell. You can force this behavior to happen when the value is changed by using the CurrentCellDirtyStateChanged event.

0 comments:

Post a Comment