Apply filter in DataGrid filled with List without changing DataSource

1

Is it possible to apply filter to a DataGridView that is "filled" with a List , without changing the DataSource of the grid?

Example: When I have a grid that uses a BindingSource I can apply a filter, such as meuBindingSource.Filter = "coluna like 'valor%'" .

Or when I fill the grid with a DataTable I can (dataGrid.DataSource as DataTable).DefaultView.RowFilter = "coluna like 'valor%'";

But when I fill in the grid with a List I can only simulate a filter, because I end up changing the DataSource of the grid. Ex.:

var source = ((IEnumerable<Tipo>)dataGrid.DataSource).ToList();
var ds = source.Where(x => x.COLUNA.EndsWith(filtro));
dataGrid.DataSource = ds.ToList();
    
asked by anonymous 18.08.2015 / 16:15

1 answer

1

Directly on the list there is no way. What you can do is create a DataView by connecting the list to it .

You have a answer in the SO showing how to do this (via DataTable ).

An alternative would be to use a third-party grid control to allow this.

I do not see other shapes now beyond what you already know.

    
18.08.2015 / 16:28