Back to Devexpress

TreeList.VirtualTreeSetCellValue Event

windowsforms-devexpress-dot-xtratreelist-dot-treelist-120d0605.md

latest7.2 KB
Original Source

TreeList.VirtualTreeSetCellValue Event

Allows changes that are made to node cells and check state to be stored.

Namespace : DevExpress.XtraTreeList

Assembly : DevExpress.XtraTreeList.v25.2.dll

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

Declaration

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

Event Data

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

PropertyDescription
CancelGets or sets whether the new value is discarded.
ColumnGets the column that contains the cell being currently processed.
IsCheckStateGets whether the TreeList.VirtualTreeGetCellValue event/ IVirtualTreeListData.VirtualTreeGetCellValue interface method is currently fired for you to save a node’s check state.
NewCellDataGets the new cell value (when VirtualTreeSetCellValueInfo.IsCheckState is false ) or the node’s new check state (when VirtualTreeSetCellValueInfo.IsCheckState is true ).
NodeGets an instance of the business object being currently processed.
OldCellDataGets the current cell’s old data.

Remarks

For more information, see Virtual Mode (Dynamic Data Loading) Using Events (Tree List Level).

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.

See Also

VirtualTreeGetCellValue

VirtualTreeGetChildNodes

Virtual Mode - Load Data Using Events

TreeList Class

TreeList Members

DevExpress.XtraTreeList Namespace