2009-04-23 84 views
6

我無法讓過濾器在DataGridView控件的DataSource的BindingSource上工作。基本上,我有LINQ查詢是BindingSource的DataSource,我想篩選結果。下面是我想要完成的一個例子。如何使用LINQ查詢過濾BindingSource作爲數據源

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 

所以,我可以看到所有的排在DataGridView控制,但過濾器沒有任何影響。如果我將BindingSource的DataSource切換爲使用DataTable,則過濾按預期工作。我錯過了什麼?

回答

4

從BindingSource的文檔:

在複雜的數據綁定 方案典型地使用的,過濾器屬性允許 您查看 數據源的子集。只有基礎列表 實施IBindingListView 接口支持過濾