Skip to main content
A newer version of this page is available. .

Virtual Mode by Binding to a Business Object

  • 3 minutes to read

The TreeList control can be bound to a business object that encapsulates a tree structure. If the business object implements the DevExpress.XtraTreeList.IVirtualTreeListData interface, the TreeList will function in Virtual Mode, in which nodes will be created on demand based on the data provided by the IVirtualTreeListData interface. For example, child nodes will only be created when you expand a certain parent node. More information on this interface is given below.

Concepts

The steps of binding to a business object are:

  1. create columns in the TreeList.Columns collection or using the Tree List Designer;
  2. implement the DevExpress.XtraTreeList.IVirtualTreeListData interface for the business object.

    The methods of this interface allow you to provide data for node creation. In addition, you can implement a dedicated method to save changes made by an end-user while editing node cells back to your business object.

The DevExpress.XtraTreeList.IVirtualTreeListData interface is defined as follows.


public interface IVirtualTreeListData {
    void VirtualTreeGetChildNodes(VirtualTreeGetChildNodesInfo info);
    void VirtualTreeGetCellValue(VirtualTreeGetCellValueInfo info);
    void VirtualTreeSetCellValue(VirtualTreeSetCellValueInfo info);
}
  • The VirtualTreeGetChildNodes method

    This method must provide a list of child objects for the current object. The number of objects returned by the method’s info.Children list identifies the number of nodes that will be created. However, note that data for node cells must be provided by the VirtualTreeGetCellValue method.

  • The VirtualTreeGetCellValue method

    This method must provide data for node cells (and optionally provide node check states - see the Node Check States section below to learn more). The currently processed cell is identified by the method’s info.Column parameter. To provide data, assign it to the info.CellData parameter.

  • The VirtualTreeSetCellValue method

    Implement this method if you need to save changes made by an end-user while editing node cells and node check states. The method provides the info.NewCellData parameter that represents the new value. Typically, you need to save this value to your business object. However, you can discard the value. To do this, set the info.Cancel parameter to true.

You can use the TreeList.EnableDynamicLoading property to specify whether a node hierarchy is created dynamically (on node expansion) or all at once on initial loading.

Node Check States

You can use the TreeListOptionsView.ShowCheckBoxes property 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 will be additionally fired 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 will be fired 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.

Task-Based Help