Skip to main content
All docs
V24.1

TreeViewControl.CustomNodeFilter Event

Allows you to use custom rules to filter nodes.

Namespace: DevExpress.Xpf.Grid

Assembly: DevExpress.Xpf.Grid.v24.1.dll

NuGet Package: DevExpress.Wpf.Grid.Core

Declaration

public event TreeViewNodeFilterEventHandler CustomNodeFilter

Event Data

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

Property Description
Handled Gets or sets whether to apply the specified filter.
Node Gets the processed node.
Visible Gets or sets whether to display the processed node.

The event data class exposes the following methods:

Method Description
CalcVisibility() Returns the node’s visibility state based on the currently applied filter.

Remarks

Use the CustomNodeFilter event to apply a custom filter condition. The TreeViewControl raises this event for each node. The e.Node property returns the processed node, and the e.CalcVisibility() method returns the node’s visibility state based on the currently applied filter.

To hide or show a node, specify the e.Visible property, and set the e.Handled property to true.

If the e.Handled property is set to false, the node’s visibility is determined by the filter applied to the TreeViewControl.

For more information, refer to the following help topic: Search and Filter Nodes.

Example

The following code sample adds the Hide Root Nodes checkbox that controls the visibility of root nodes:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="36"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <CheckBox Name="chkHideRoot" Grid.Row="0" Margin="7,0,0,0" 
              VerticalAlignment="Center"
              Content="Hide Root Nodes"
              Checked="chk_CheckedOrUnchecked"
              Unchecked="chk_CheckedOrUnchecked"/>
    <dxg:TreeViewControl x:Name="treeview"
                         Grid.Row="1"
                         ItemsSource="{Binding EmployeeDepartments}" 
                         ChildNodesPath="Employees" 
                         TreeViewFieldName="Name"
                         CustomNodeFilter="treeview_CustomNodeFilter"/>
</Grid>
void treeview_CustomNodeFilter(object sender, DevExpress.Xpf.Grid.TreeList.TreeViewNodeFilterEventArgs e) {
    if (chkHideRoot.IsChecked.Value && e.Node.Level == 0) {
        e.Visible = false;
        e.Handled = true;
    }
}
void chk_CheckedOrUnchecked(object sender, RoutedEventArgs e) {
    treeview.RefreshData();
}
See Also