What it makes that collections are bindable? Is there common interface for List, DataTable with can bind to same control?
To explain how List<T> and DataTable work (the footnote of the question), read the following but noting that:
List<T> implements IList and has a public T this[int index] {get;} which is used for resolving metadataDataTable implements IListSource, which provides the table's default DataView; the DataView implements IList, and implements ITypedList to provide metadataCollections bind in the following order:
IListSource; if available the IList is obtained via GetList()IList; if unavailable an exception is thrownthen metadata for the IList is queried:
IList is tested for ITypedList; if available this is used via GetPropertiesIList is tested for a public typed (non-object) indexer, i.e. public Foo this[int index] { get; } - if found, Foo is implied as the type and metadata obtained via TypeDescriptor.GetProperties(Type)GetType() for the type, and metadata obtained via TypeDescriptor.GetProperties(Type)we now have access to the items (IList) and their metadata; additional support (optional) is provided via IBindingList (provides 2-way binding and basic sorting etc), IBindingListView (provides advanced sorting, filtering, etc), ICancelAddNew and IRaiseItemChangedEvents.
For most common scenarios (show data and push changes back) List<T> is fine; if you need to show unrelated updates as they happen BindingList<T> helps - but note that to support member level updates (as opposed to just add/remove/etc) the T must implement INotifyPropertyChanged
For reference, "metadata" here means "a set of PropertyDescriptors" (1 per column/property), which provide access to the underlying data (when supplied with an object), and information about the member itself (name, type, etc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With