Occurs before a node is expanded.
public event TreeListNodeAllowEventHandler NodeExpanding
Public Event NodeExpanding As TreeListNodeAllowEventHandler
The NodeExpanding event's data class is TreeListNodeAllowEventArgs. The following properties provide information specific to this event:
|Allow||Gets or sets whether the operation is allowed.|
|Handled||Gets or sets a value that indicates the present state of the event handling for a routed event as it travels the route. Inherited from RoutedEventArgs.|
|Node||Gets the processed node. Inherited from TreeListNodeEventArgs.|
|OriginalSource||Gets the original reporting source as determined by pure hit testing, before any possible Source adjustment by a parent class. Inherited from RoutedEventArgs.|
|RoutedEvent||Gets or sets the RoutedEvent associated with this RoutedEventArgs instance. Inherited from RoutedEventArgs.|
|Row||Gets the processed row. Inherited from TreeListNodeEventArgs.|
|Source||Gets or sets a reference to the object that raised the event. Inherited from RoutedEventArgs.|
The event data class exposes the following methods:
|InvokeEventHandler(Delegate, Object)||When overridden in a derived class, provides a way to invoke event handlers in a type-specific way, which can increase efficiency over the base implementation. Inherited from RoutedEventArgs.|
|OnSetSource(Object)||When overridden in a derived class, provides a notification callback entry point whenever the value of the Source property of an instance changes. Inherited from RoutedEventArgs.|
Handle this event to:
- Cancel the action by setting the event parameter's TreeListNodeAllowEventArgs.Allow property to false;
- Dynamically create child nodes. In this instance, when expanding a node, you do not know whether it has child nodes or not. If the node has no child nodes, hide the expand button by setting the TreeListNode.IsExpandButtonVisible property to false.
After a node has been expanded, the TreeListView.NodeExpanded event is raised.
To learn more, see Expanding and Collapsing Nodes .
In this example, the TreeListView displays the file/folder tree. Child nodes that correspond to sub folders or files contained within a folder are dynamically created when a parent node is being expanded.
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-dynamically-load-nodes-e3109.
<Window x:Class="DynamicNodeLoading.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"> <Grid> <dxg:GridControl Name="grid"> <dxg:GridControl.Columns> <dxg:GridColumn FieldName="Name" /> <dxg:GridColumn FieldName="ItemType" /> <dxg:GridColumn FieldName="Size" /> <dxg:GridColumn FieldName="FullName" /> </dxg:GridControl.Columns> <dxg:GridControl.View> <dxg:TreeListView Name="treeListView1" AutoWidth="True" NodeExpanding="treeListView1_NodeExpanding"/> </dxg:GridControl.View> </dxg:GridControl> </Grid> </Window>