[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Collapse]Tree List
   [Expand]Product Information
   [Collapse]Feature Center
    [Collapse]Data Binding
      Bound Mode
      Tree Generation Algorithm in the Tree List
      Virtual Mode (Dynamic Data Loading) Using Events (Tree List Level)
      Virtual Mode - Binding to a Hierarchical Business Object (Data Source Level)
      Unbound Mode
      Unbound Columns
      Posting Data to a Connected Database in ADO.NET
    [Expand]Nodes
    [Expand]Data Editing
    [Expand]Data Presentation
    [Expand]Sorting
    [Expand]Filtering
    [Expand]Summaries
    [Expand]Appearances and Look And Feel
    [Expand]Focus, Selection and Navigation
     Formatting Cell Values
    [Expand]Miscellaneous
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]Examples
   [Expand]End User Capabilities
   [Expand]Member Tables
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
  [Expand]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Virtual Mode - Binding to a Hierarchical Business Object (Data Source Level)

In a hierarchical data source, items are linked by "parent-child" relationships at the data source level. A typical hierarchical data source is a business object that returns child items in a collection property. A TreeList bound to a list of these business objects automatically builds a node hierarchy. See Implement Hierarchical Data Source Using Collection Property (ChildListFieldName) for details.

Your hierarchical data source may not provide this collection property or you may need greater control over the interaction between the TreeList and the data source. In these cases, you can still provide data hierarchy information to the TreeList at the data source level by implementing the IVirtualTreeListData interface. The TreeList bound to this data source only loads and saves data using this interface's methods. See Implement Hierarchical Data Source Using IVirtualTreeListData Interface for more information.

It is also possible to provide information on a data hierarchy at the TreeList level by handling the control's dedicated events. See Virtual Mode (Dynamic Data Loading) Using Events (Tree List Level).

Expanded Implement a Hierarchical Data Source Using Collection Property

You can create a hierarchical business object that returns children using a collection property. When a TreeList is bound to a list of these business objects, it automatically builds a node hierarchy by iterating through the specified collection property. This binding approach does not require additional interfaces at the data source level.

Set up the TreeList as follows:

  1. Create a business object and define a public collection property that returns child items.
  2. Bind a list of business objects to the TreeList's TreeList.DataSource property.
  3. Set the TreeList.ChildListFieldName property to this collection property name.
When you run the application, the TreeList control will automatically build a node hierarchy by iterating through the business object list and specified child item collections.

Expanded Example

This example binds a TreeList to a list of Employee objects. The control creates child nodes from employees' Subordinates collections.

Demo: Registry Viewer module in the XtraTreeList MainDemo

Expanded Implement Hierarchical Data Source Using IVirtualTreeListData Interface

If a business object contains hierarchical data, you can present this hierarchy in the TreeList by implementing the DevExpress.XtraTreeList.IVirtualTreeListData interface for the business object. The TreeList will create nodes on demand based on the data the IVirtualTreeListData interface methods provide. The interface methods fire when the TreeList needs to generate root and child nodes, display node values, and when node values are modified.

  1. Create a business object that supports the DevExpress.XtraTreeList.IVirtualTreeListData interface, and handle the following two interface methods.

    - IVirtualTreeListData.VirtualTreeGetChildNodes - Implement this method to provide a child object list to create child nodes.

    - IVirtualTreeListData.VirtualTreeGetCellValue - This method must provide data for the specified node cells (and optionally provide node check states - see the Node Check States section below to learn more).

  2. If you need to save changes made by an end-user while editing node cells and node check states, implement the following interface method.

    - IVirtualTreeListData.VirtualTreeSetCellValue - This method provides the info.NewCellData parameter that specifies the new value. Typically, you need to save this value to your business object. However, you can discard the value by setting the info.Cancel parameter to true

  3. Bind a business object instance to the TreeList.DataSource property.

You can use the TreeList.EnableDynamicLoading property to build a node hierarchy on node expansion.

Expanded Example

The following example shows how to support a tree structure for a business object (Node class) using the IVirtualTreeListData interface. The example implements all three interface methods.

The following code creates a Node class object and binds it to TreeList.

The image below illustrates the result.

Expanded Node Check States

You can use the TreeListOptionsView.CheckBoxStyle, TreeListOptionsView.RootCheckBoxStyle, and TreeListNode.ChildrenCheckBoxStyle properties to enable built-in check boxes that allow end-users to check certain nodes. In this case, you can set the TreeListOptionsBehavior.AllowBoundCheckBoxesInVirtualMode property to true to use the IVirtualTreeListData.VirtualTreeGetCellValue and VirtualTreeSetCellValue methods to specify not only node values, but also node check states.

When the TreeListOptionsBehavior.AllowBoundCheckBoxesInVirtualMode property is true, the IVirtualTreeListData.VirtualTreeGetCellValue interface method additionally fires for each node with the VirtualTreeGetCellValueInfo.IsCheckState parameter set to true. To provide a node's check state, assign it to the VirtualTreeGetCellValueInfo.CellData parameter (when IsCheckState is true). Similarly, when an end-user modifies a node's check state, the IVirtualTreeListData.VirtualTreeSetCellValue interface method fires with the VirtualTreeSetCellValueInfo.IsCheckState parameter set to true. In this case, save the node's check state (which is stored in the VirtualTreeSetCellValueInfo.NewCellData parameter) according to your logic.

Is this topic helpful?​​​​​​​