Bound Mode
- 3 minutes to read
Online Video
Learn how to create a Tree List control, bind it to data, and customize the control’s view and behavior options.
The Tree List control can be bound to any traditional data source: a BindingSource, BindingList<T>, List<T>, DataTable, DataView and DataSet objects, objects that implement specific interfaces (e.g., IList, ITypedList and IBindingList), SQL data, XML data, Excel data sources, etc. See this help topic for the complete list of available data sources: Data Binding Common Concepts.
As any other DevExpress data-aware control, Tree List shows data from its sources as is. If you need to filter or sort records, or merge multiple data sources into one, do that at the data source level before you bind a Tree List to this source.
Use the following properties to bind Tree List to data.
- TreeList.DataSource - Specifies the data source.
- TreeList.DataMember - If the bound data source contains multiple tables, specify the target table with this property.
- TreeList.KeyFieldName - This field should store nodes’ unique IDs.
- TreeList.ParentFieldName - This field must contain the parent node’s ID for each node.
- TreeList.RootValue - Allows the Tree List control to determine root nodes.
More information is provided below.
TreeList Control Binding Specifics
Like other data-aware controls, the Tree List control provides the traditional TreeList.DataSource and TreeList.DataMember properties for binding. Use the latter property if the TreeList.DataSource is a DataSet object (DataSets can contain multiple tables).
Due to the hierarchical structure of Tree List nodes, the bound data source must contain two fields to identify the relationship between records. Assign these two field names to the following properties:
- TreeList.KeyFieldName - This field should store nodes’ unique IDs.
- TreeList.ParentFieldName - This field must contain the parent node’s ID for each node.
Besides these two properties, you also need to specify the TreeList.RootValue property, which allows the Tree List control to determine root nodes. Data source records that have the RootValue in the ParentFieldName field will be regarded as root nodes. To learn more about the node hierarchy setting-up, see the following topic:
Note
- Although Tree List allows you to display records from an underlying data source as a plain list (the TreeList.KeyFieldName and TreeList.ParentFieldName properties must be empty), we recommend using the Data Grid control for this task.
- Dynamic data loading (virtual mode) is not supported in bound mode.
- To sort data, do not use the methods provided by the bound data source. Instead, sort data using methods provided by the Tree List control. See Sorting to learn more.
The topics in the following section describe common data-binding concepts and scenarios that are applied to the Tree List, Data Grid, and other data-aware controls.
General Data Binding Concepts
- Traditional Data Binding Methods
- Data Source Configuration Wizard
- Data Binding Mechanism in ADO.NET
- Binding to SQL Data
- Binding Controls to XML Data
- Binding to Excel Data Sources
- Binding Controls to Data Created at Runtime
- Tutorial: Entity Framework Data
- Obtaining Fields Available in Data Source
- Data Annotation Attributes