This is a migrated thread and some comments may be shown as answers.

Define custom filter predicate in listview

1 Answer 98 Views
ListView
This is a migrated thread and some comments may be shown as answers.
kim
Top achievements
Rank 1
kim asked on 02 Aug 2011, 09:33 AM
Is it possible to do custom filtering in the listview like it is possible in radgridview?

I want to do a contains filter on an integer column.  But this is not possible. In radgridview this was possible by setting the MasterTemplate.FilterPredicate.

1 Answer, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 04 Aug 2011, 03:43 PM
Hi Kim,

You can achieve this functionality using the DataView property of the root ListViewElement. Here is a simple example:

public partial class ListViewForm1 : Form
{
    public ListViewForm1()
    {
        InitializeComponent();
        radListView1.EnableFiltering = true;
    }
 
    private void ListViewForm1_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'northwindDataSet.Customers' table. You can move, or remove it, as needed.
        this.customersTableAdapter.Fill(this.northwindDataSet.Customers);
 
        this.radListView1.ListViewElement.DataView.Filter = MyFilter;
    }
 
    private bool MyFilter(ListViewDataItem item)
    {
        if (item.Value.ToString().Contains('C'))
        {
            return true;
        }
 
        return false;
    }
}

For Q2 2011 SP1 release the RadLisView control will has its own FilterPredicate property the make the API easier to use.

All the best,
Julian Benkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
ListView
Asked by
kim
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Share this question
or