New to Telerik UI for WinForms? Download free 30-day trial

Custom Filtering

Custom filtering is a flexible mechanism for filtering RadTreeView nodes by using custom logic. It has a higher priority than the applied FilterDescriptors.

In order to apply custom logic for filtering, you have to create a Predicate. Here is an example of a Predicate which will return just the nodes which text is longer than one char:

Creating predicate

private bool FilterNode(RadTreeNode node)
{
    if (node.Text.Length > 1)
    {
        return true;
    }
    return false;
}

Private Function FilterNode(node As RadTreeNode) As Boolean
    If node.Text.Length > 1 Then
        Return True
    End If
    Return False
End Function

Here you have nodes from 1-100 After the filtering the nodes are only from 10-100, since nodes 1-9 contain just one char as text
WinForms RadTreeView Default Order WinForms RadTreeView Custom Filtering

To set the Predicate to RadTreeView, use the FilterPredicate property of the control:

Applying predicate

radTreeView1.TreeViewElement.FilterPredicate = FilterNode;

RadTreeView1.TreeViewElement.FilterPredicate = AddressOf FilterNode

At the end, in order to apply the filter to the control, just set the Filter property to any string, which will invoke the filtering operation:

Invoke filtering

private void radButton1_Click(object sender, EventArgs e)
{
    this.radTreeView1.Filter = "Custom";
}

Private Sub RadButton1_Click(sender As System.Object, e As System.EventArgs) Handles RadButton1.Click
    Me.RadTreeView1.Filter = "Custom"
End Sub

See Also

In this article