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

Filtering

RadListView allows filtering operations in all views. To enable filtering operations use the EnableFiltering property of the control:

Enable Filtering

radListView1.EnableFiltering = true;

RadListView1.EnableFiltering = True

Once the filtering is enabled, we have to create a new FilterDescriptor and assign its PropertyName, FilterOperator and SearchCriteria. First, let’s filter the items by their value and look for items starting with “Local”.

Filter by Value

FilterDescriptor valueFilter = new FilterDescriptor("Value", FilterOperator.StartsWith, "Local");
radListView1.FilterDescriptors.Add(valueFilter);

Dim valueFilter As New FilterDescriptor("Value", FilterOperator.StartsWith, "Local")
RadListView1.FilterDescriptors.Add(valueFilter)

Before Filtering After Filtering
WinForms RadListView Before Filtering WinForms RadListView After Filtering

When a column name is specified as PropertyName of the filter descriptor, RadListView will filter by the values of the specified column:

Filter by type

FilterDescriptor typeFilter = new FilterDescriptor("Type", FilterOperator.Contains, "Disk");
radListView1.FilterDescriptors.Add(typeFilter);

Dim typeFilter As New FilterDescriptor("Type", FilterOperator.Contains, "Disk")
RadListView1.FilterDescriptors.Add(typeFilter)

Before After
WinForms RadListView Before WinForms RadListView After

Custom Filtering

RadListView provides a flexible mechanism for defining a custom filtering logic by using a custom filter predicate. The following example demonstartes how to apply a FilterPredicate in order to filter all items which contain "C":

Custom FilterPredicate

private bool MyFilter(ListViewDataItem item)
{
    if (item.Value.ToString().Contains("C"))
    {
        return true;
    }
    return false;
}

Private Function MyFilter(item As ListViewDataItem) As Boolean
    If item.Value.ToString().Contains("C") Then
        Return True
    End If
    Return False
End Function

Apply the custom FilterPredicate

this.radListView1.ListViewElement.DataView.Filter = MyFilter;

Me.RadListView1.ListViewElement.DataView.Filter = AddressOf MyFilter

Figure 3: Custom Filtering

WinForms RadListView Custom Filtering

See Also

In this article