Back to Devexpress

TreeViewControl.CustomNodeFilter Event

wpf-devexpress-dot-xpf-dot-grid-dot-treeviewcontrol-9f644d22.md

latest4.6 KB
Original Source

TreeViewControl.CustomNodeFilter Event

Allows you to use custom rules to filter nodes.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public event TreeViewNodeFilterEventHandler CustomNodeFilter
vb
Public Event CustomNodeFilter As TreeViewNodeFilterEventHandler

Event Data

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

PropertyDescription
HandledGets or sets whether to apply the specified filter.
NodeGets the processed node.
VisibleGets or sets whether to display the processed node.

The event data class exposes the following methods:

MethodDescription
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:

xaml
<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>
csharp
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();
}
vb
Private Sub treeview_CustomNodeFilter(ByVal sender As Object, ByVal e As DevExpress.Xpf.Grid.TreeList.TreeViewNodeFilterEventArgs)
    If chkHideRoot.IsChecked.Value AndAlso e.Node.Level = 0 Then
        e.Visible = False
        e.Handled = True
    End If
End Sub

Private Sub chk_CheckedOrUnchecked(ByVal sender As Object, ByVal e As RoutedEventArgs)
    treeview.RefreshData()
End Sub

See Also

TreeViewControl Class

TreeViewControl Members

DevExpress.Xpf.Grid Namespace