views:

9

answers:

1

I have a winForms DataGridView bound to a List<MyObjectType>. My problem is that once I do the initial myDataGridView.DataSource = myObjectList; that adding/removing elements from the list is not reflected in the displayed DataGridView even though in the debugger the row count on myDataGridView.DataSource does update.

I'm able to force the DGV to update the displayed rows if I null the datasource before reassigning the list to it. This looks ugly though and I'm wondering if I didn't miss an easier way to do this.

myDataGridView.DataSource = null;
myDataGridView.DataSource = myObjectList;
+1  A: 

The List<T> collection does not support change notifications, so the DataGridView will never be able to detect when you add/remove elements. Consider using ObservableCollection<T>, which does support change notifications.

Bradley Smith