Obtaining Fields Available in Data Source
- 2 minutes to read
Data-aware controls (e.g., Grid Control and XtraTreeList) can be bound to various data sources (e.g., BindingList<T>, List<T>, IList and ITypedList). When bound to a data source, the control needs to determine fields (properties) available in the data source that can potentially provide data for columns. For instance, information on available fields allows for automatic column creation.
Information on the fields available in the data source is retrieved as follows.
- If the data source implements the ITypedList interface, this information is obtained using the methods of this interface.
- If the data source provides an indexer , available properties in the data source match public properties provided by the indexer's return type.
- If the data source derives from the List<T> type, available properties in the data source are those exposed by the generic type T.
If the data source implements the IList interface, the first item is retrieved from the IList, and this item's public properties will determine the properties available in the data source for a data-aware control.
Information on the first item's properties is retrieved only when assigning the data source to the data-aware control. Ensure that the data source contains at least one item of a target type prior to binding the data source to the control.