What would be the best collection to use when binding a list of data to a DataGridview in C#? I’m currently using just a Generic List but the data grid doesn’t update when there is objects added or removed from the list. I’ve looked at using a BindingList or a ObservableCollection, but can’t decide which would be best to use that would update and be easy to sort/filter without having to rebind to the data grid. I’m currently working in windows form on .Net 3.5 framework with plans to move over to WPF soon.
Share
ObservableCollection<T>won’t work for aDataGridView: it implementsINotifyCollectionChanged, notIBindingList, and theDataGridViewdoesn’t know aboutINotifyCollectionChanged. It is intended for WPF bindings and is not used in Windows FormsBindingList<T>is a good option, but note that it doesn’t support sorting or filtering out of the box. However, you can find some custom implementations of these features on the web.DataTableis probably your best option if you need sorting and/or filtering capability