Back to Devexpress

TreeList.VirtualTreeGetChildNodes Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-0aa91f26.md

latest12.2 KB
Original Source

TreeList.VirtualTreeGetChildNodes Event

Allows you to supply root and child nodes, when populating the Tree List control with data dynamically.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

NuGet Packages : DevExpress.Win.Navigation, DevExpress.Win.TreeList

Declaration

csharp
[DXCategory("VirtualTree")]
public event VirtualTreeGetChildNodesEventHandler VirtualTreeGetChildNodes
vb
<DXCategory("VirtualTree")>
Public Event VirtualTreeGetChildNodes As VirtualTreeGetChildNodesEventHandler

Event Data

The VirtualTreeGetChildNodes event's data class is VirtualTreeGetChildNodesInfo. The following properties provide information specific to this event:

PropertyDescription
ChildrenGets or sets the collection of children for the currently processed business object.
NodeGets an instance of the business object being currently processed.

Remarks

The TreeList.VirtualTreeGetChildNodes, TreeList.VirtualTreeGetCellValue and TreeList.VirtualTreeSetCellValue events support dynamic data loading.

To enable dynamic data loading mode, set the TreeList.DataSource property to any object, except objects that implement the IList or IVirtualTreeListData interface. Then handle the VirtualTreeGetChildNodes and TreeList.VirtualTreeGetCellValue events to supply data. To respond to user edits, handle the TreeList.VirtualTreeSetCellValue event.

The VirtualTreeGetChildNodes event fires on demand.

Read the following topic for detailed information: Virtual Mode (Dynamic Data Loading) Using Events (Tree List Level).

Note

Reset the TreeList’s DataSource property to reload the tree in virtual mode.

Example

The following demo shows how to use the TreeList.VirtualTreeGetChildNodes and TreeList.VirtualTreeGetCellValue events to specify data for a Tree List control.

Run Demo: Explorer(Virtual Tree)

The navigationTreeList control in this demo displays directories of the file system. Instead of loading the entire directory structure on application startup, this control loads directories on demand (when a user expands a specific directory).

The TreeList.VirtualTreeGetChildNodes event is handled to dynamically load child items (directories) for a specific node. The Tree List control automatically creates nodes for all child items that the VirtualTreeGetChildNodes event handler supplies.

The TreeList.VirtualTreeGetCellValue event handler specifies values for loaded children.

csharp
navigationTreeList.VirtualTreeGetChildNodes += OnNavigationTreeListGetChildNodes;
navigationTreeList.VirtualTreeGetCellValue += OnNavigationTreeListGetCellValue;
//...
void OnNavigationTreeListGetChildNodes(object sender, VirtualTreeGetChildNodesInfo e) {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    e.Children = ((Item)e.Node).GetDirectories();
    Cursor.Current = current;
}

void OnNavigationTreeListGetCellValue(object sender, VirtualTreeGetCellValueInfo e) {
    e.CellData = ((Item)e.Node).DisplayName;
}

//...
public abstract class Item : IFileImage {
    //...
    public string DisplayName {get; private set;}
    public abstract List<Item> GetDirectories();
}
vb
AddHandler Me.navigationTreeList.VirtualTreeGetChildNodes, AddressOf Me.OnNavigationTreeListGetChildNodes
AddHandler Me.navigationTreeList.VirtualTreeGetCellValue, AddressOf Me.OnNavigationTreeListGetCellValue
'...
Private Sub OnNavigationTreeListGetChildNodes(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.VirtualTreeGetChildNodesInfo)
    Dim current As System.Windows.Forms.Cursor = System.Windows.Forms.Cursor.Current
    System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
    e.Children = CType(e.Node, DevExpress.XtraTreeList.Demos.Item).GetDirectories()
    System.Windows.Forms.Cursor.Current = current
End Sub

Private Sub OnNavigationTreeListGetCellValue(ByVal sender As Object, ByVal e As DevExpress.XtraTreeList.VirtualTreeGetCellValueInfo)
    e.CellData = CType(e.Node, DevExpress.XtraTreeList.Demos.Item).DisplayName
End Sub

Public MustInherit Class Item
    Implements DevExpress.XtraTreeList.Demos.IFileImage
    '...
    Private _DisplayName As String, _Name As String, _FullName As String
    Public MustOverride Function GetDirectories() As List(Of DevExpress.XtraTreeList.Demos.Item)
End Class

Handle the TreeList.VirtualTreeSetCellValue event for the opposite task: if the Tree List is editable, you can write new cell values entered by users to a data source.

csharp
using DevExpress.XtraTreeList;

void OnVirtualTreeSetCellValue(object sender, VirtualTreeSetCellValueInfo e) {
    ((Item)e.Node).DisplayName = e.NewCellData.ToString();
}
vb
Imports DevExpress.XtraTreeList

Private Sub OnVirtualTreeSetCellValue(ByVal sender As Object, ByVal e As VirtualTreeSetCellValueInfo)
    CType(e.Node, Item).DisplayName = e.NewCellData.ToString()
End Sub

See the Explorer (Virtual Tree) demo for the complete code.

The following code snippets (auto-collected from DevExpress Examples) contain references to the VirtualTreeGetChildNodes event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheet-chart-api/CS/SpreadsheetChartAPISamples/Form1.cs#L153

csharp
treeList.VirtualTreeGetChildNodes += treeList_VirtualTreeGetChildNodes;
treeList.VirtualTreeGetCellValue += treeList_VirtualTreeGetCellValue;

winforms-spreadsheet-pivot-table-api/CS/SpreadsheetPivotTableExamples/Form1.cs#L141

csharp
treeList.VirtualTreeGetChildNodes += treeList_VirtualTreeGetChildNodes;
treeList.VirtualTreeGetCellValue += treeList_VirtualTreeGetCellValue;

winforms-spreadsheetcontrol-api-part-3/CS/SpreadsheetControl_API_Part03/Form1.cs#L314

csharp
treeList.OptionsView.ShowIndicator = false;
treeList.VirtualTreeGetChildNodes += treeList_VirtualTreeGetChildNodes;
treeList.VirtualTreeGetCellValue += treeList_VirtualTreeGetCellValue;

winforms-richeditcontrol-common-api/CS/RichEditAPISample/Form1.cs#L420

csharp
treeList.VirtualTreeGetChildNodes += treeList_VirtualTreeGetChildNodes;
treeList.VirtualTreeGetCellValue += treeList_VirtualTreeGetCellValue;

winforms-richedit-document-api/CS/RichEditAPISample/Form1.cs#L408

csharp
treeList.OptionsView.ShowIndicator = false;
treeList.VirtualTreeGetChildNodes += treeList_VirtualTreeGetChildNodes;
treeList.VirtualTreeGetCellValue += treeList_VirtualTreeGetCellValue;

winforms-spreadsheet-chart-api/VB/SpreadsheetChartAPISamples/Form1.vb#L148

vb
AddHandler treeList.VirtualTreeGetChildNodes, AddressOf treeList_VirtualTreeGetChildNodes
AddHandler treeList.VirtualTreeGetCellValue, AddressOf treeList_VirtualTreeGetCellValue

winforms-spreadsheet-pivot-table-api/VB/SpreadsheetPivotTableExamples/Form1.vb#L134

vb
AddHandler treeList.VirtualTreeGetChildNodes, AddressOf treeList_VirtualTreeGetChildNodes
AddHandler treeList.VirtualTreeGetCellValue, AddressOf treeList_VirtualTreeGetCellValue

winforms-spreadsheetcontrol-api-part-3/VB/SpreadsheetControl_API_Part03/Form1.vb#L317

vb
treeList.OptionsView.ShowIndicator = False
AddHandler treeList.VirtualTreeGetChildNodes, AddressOf treeList_VirtualTreeGetChildNodes
AddHandler treeList.VirtualTreeGetCellValue, AddressOf treeList_VirtualTreeGetCellValue

winforms-richeditcontrol-common-api/VB/RichEditAPISample/Form1.vb#L412

vb
AddHandler treeList.VirtualTreeGetChildNodes, AddressOf treeList_VirtualTreeGetChildNodes
AddHandler treeList.VirtualTreeGetCellValue, AddressOf treeList_VirtualTreeGetCellValue

winforms-richedit-document-api/VB/RichEditAPISample/Form1.vb#L413

vb
treeList.OptionsView.ShowIndicator = False
AddHandler treeList.VirtualTreeGetChildNodes, AddressOf treeList_VirtualTreeGetChildNodes
AddHandler treeList.VirtualTreeGetCellValue, AddressOf treeList_VirtualTreeGetCellValue

See Also

VirtualTreeGetCellValue

VirtualTreeSetCellValue

Virtual Mode - Load Data Using Events

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace