Question

i have a sql table "Activity" which includes .ID , .Activ_Code , .Name , .Start , .End

Dim BS as BindingSource
Dim DGView as Datagridview


BS.Datasource=(From x in Dbase.Activity select x)
BS.Filter="Activ_Code=3"
DGView.datasource=BS

this shows all fields from "Activity" Table. i changed Filter property to "Activ_Code='3'" and "Activ_Code LIKE 3" but none of them works.

Was it helpful?

Solution

From MSDN:

Only underlying lists that implement the IBindingListView interface support filtering.

The datasource is just an IEnumerable. You have to filter in the LINQ query itself. For instance:

Dim mainList = (From x in Dbase.Activity select x).ToList
BS.Datasource=(From x in mainList.Where(...) select x)

and put your filter at the dots. Each time you set the data source to a new filtered list, the objects in the list won't be affected because they are not re-fetched from the database.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top