Skip to main content

Virtual Mode (Dynamic Data Loading) Using Events (Tree List Level)

  • 3 minutes to read

The Tree List control supports dynamic data loading using events. You can handle specific events to provide data for the Tree List control dynamically, and save changes made by an end-user to cells, if required.

The basic steps to implement dynamic data loading are as follows.

  1. Create required columns that will display your data. You can do this at both design time and in code by modifying the TreeList.Columns collection.
  2. Specify the TreeList.DataSource property. Do not assign objects of the following types to this property.

    • Objects that implement the IList interface. In this case, the Tree List control will switch to bound mode and populate nodes automatically.
    • Objects that implement the IVirtualTreeListData interface. Otherwise, the Tree List control will fetch data from this object.
  3. By default, a node hierarchy is created dynamically (on node expansion). To change this behavior and create the entire node hierarchy at once, set the TreeList.EnableDynamicLoading property to false.
  4. Handle the TreeList.VirtualTreeGetChildNodes event. This event is used to supply lists of objects to be represented as nodes. The event fires dynamically on demand (for instance, when end-users expand nodes). The event’s Node parameter identifies the parent object whose child nodes must be retrieved using the event. Set the event’s Children parameter to create the required amount of child nodes for this parent node.

    The VirtualTreeGetChildNodes event also fires to retrieve objects representing root nodes. To identify this situation, check the Node parameter. It will refer to the object assigned to the TreeList.DataSource property.

  5. Handle the TreeList.VirtualTreeGetCellValue event to provide data for blank node cells and node check states (see the Node Check States section below). The event fires dynamically for each node object supplied by the TreeList.VirtualTreeGetChildNodes event and for each Tree List column. You can use the event’s Node parameter to identify the underlying object and fetch the required data, if necessary. The currently processed Tree List column is specified by the Column parameter. To supply data, assign it to the event’s CellData parameter.
  6. Handle the TreeList.VirtualTreeSetCellValue event, if you need to respond to changing node cells and check states by an end-user, and save this data. The event provides parameters to identify the current node cell. It also contains the Cancel parameter that allows you to discard a value entered by an end-user.

Node Check States

The TreeList nodes can display check boxes that allow end-users to check certain nodes (see Node Checking - Checkboxes and Radio Buttons). By default, the TreeList.VirtualTreeGetCellValue event is used to supply node values. If the TreeListOptionsBehavior.AllowBoundCheckBoxesInVirtualMode option is enabled, this event is also fired, so you provide a node’s check state. Read the IsCheckState parameter to learn if the event is fired to query a check state. If it returns true, assign the check state to the event’s CellData parameter.

Similarly, when an end-user modifies a node’s check state, the TreeList.VirtualTreeSetCellValue event fires (if the TreeListOptionsBehavior.AllowBoundCheckBoxesInVirtualMode option is enabled) with the IsCheckState parameter set to true. In this case, you can save the node’s new check state (which is stored in the NewCellData parameter) according to your logic.

Example

See Also