views:

1164

answers:

1

I'm having trouble getting a filter to work on a BindingSource that is the DataSource for a DataGridView control. Basically, I have LINQ query that is the DataSource for the BindingSource and I would like to filter down the results. Below is an example of what I'm trying to accomplish.

Dim query = From row In dataTable _
            Select New MyRow(row)

Dim bs As New BindingSource()
bs.DataSource = query.ToList()

grid.DataSource = bs

bs.Filter = "Col1 = 'value'"

...

Public Class MyRow
    Private _key As String
    Private _col1 As String

    Public Sub New(ByVal row As DataTableRow)
        _key = GetNewKeyValue()
        _col1 = row.Col1
    End Sub

    Public ReadOnly Property Key() As String
        Get
            Return _key
        End Get
    End Property

    Public ReadOnly Property Col1() As String
        Get
            Return _col1
        End Get
    End Property
End Class

So, I can see all the rows in the DataGridView control but the filter doesn't have any effect. If I switch the BindingSource's DataSource to use a DataTable, then the filtering works as expected. What am I missing?

+2  A: 

From the BindingSource documentation:

Typically used in complex data-binding scenarios, the Filter property allows you to view a subset of the DataSource. Only underlying lists that implement the IBindingListView interface support filtering

Sven Künzler