Apply filter to Datagrid populated with List without changing the Datasource

Asked

Viewed 1,484 times

1

It is possible to apply filter to a DataGridView which is "filled" with a List, without altering the DataSource grid?

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

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

But when I fill the grid with a List I can only get 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();

1 answer

1


Directly in the list there is no way. What you can do is create a DataView connecting the list to her.

Has a response in the OS showing how to do this (through a DataTable).

An alternative would be to use a grid of third parties that allow this.

I see no other ways now than what you already know.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.