Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't bound DataGridView cells being updated?

I have successfully bound my DataGridView to a list. But, the grid doesn't refresh when I programatically change some of the properties of one of the objects within the list. If I click in the cell (or minimize and then maximize form), the displayed value is refreshed.

I read here that I should use a BindingList. The list I am using is an interface type which doesn't implement IBindingList. But, the concrete type being used to initialize the list does inherit off of BindingList. Any ideas?

like image 888
bsh152s Avatar asked Oct 11 '11 16:10

bsh152s


1 Answers

Your list must implement IBindingList (or be a BindingList) and your object must implement INotifyPropertyChanged. Both conditions are required for your DataGridView to bind properly.

So if your data source would be, for instance, MyList<MyClass>, MyList must implement IBindingList and MyClass must implmenent INotifyPropertyChanged.

Here is a neat example: http://crazorsharp.blogspot.com/2009/06/inotifypropertychanged-how-to-and-when.html

like image 67
Ahmet Avatar answered Oct 30 '22 08:10

Ahmet