Skip to main content

Automatic Data Binding

  • 2 minutes to read

TreeView has a unique built-in ability to automatically retrieve data from a data source that supports the IHierarchicalEnumerable or IHierarchicalDataSource interface. This topic describes the conditions that allow TreeView to bind automatically.

TreeView can recognize data items and retrieve some node characteristics from the data fields named in a specific way. If however, any of the data-related properties of a TreeView (such as TextField, ImageUrlField, etc.) have been set, then the mapping of the associated MVCxTreeViewNode object properties will proceed according to Data Binding Using Mapping Properties.

Data fields and node properties name match

During binding, TreeView implements its automatic binding ability by retrieving node characteristics from those data fields whose names coincide with certain property names of an MVCxTreeViewNode object. The table below lists the names of the node object properties that can be mapped during automatic binding, and the matching data field names you should use in the data source for mapping to work.

Node properties that can be set automatically Data field names
MVCxTreeViewNode.Checked Checked
MVCxTreeViewNode.Enabled Enabled
MVCxTreeViewNode.Image.Url ImageUrl
MVCxTreeViewNode.Name Name
MVCxTreeViewNode.NavigateUrl NavigateUrl
MVCxTreeViewNode.Target Target
MVCxTreeViewNode.Text Text
MVCxTreeViewNode.ToolTip ToolTip

The following image illustrates the process of data retrieval during automatic binding to a particular type of data source - XmlDataSource.

TreeView_BindingToXml

Binding to a Site Map

Since the properties of a SiteMapNode object have specific names, TreeView is designed to automatically bind to a Site Map source, with node attributes with similar names. In the process of binding, corresponding properties of individual MVCxTreeViewNode objects are automatically associated with these item attributes and mapped accordingly. See the table below for name correspondence.

Site Map node attributes Corresponding TreeViewNode object properties
Description MVCxTreeViewNode.ToolTip
Title MVCxTreeViewNode.Text
Url MVCxTreeViewNode.NavigateUrl

Note

The structure of a Site Map allows some flexibility in the naming of item attributes. After TreeView detects the item attributes named title, url and description in the bound Site Map source, the conditions described in the above section apply.