我在让过滤器在BindingSource上工作时遇到麻烦,该BindingSource是DataGridView控件的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,则过滤将按预期进行。我想念什么?
最佳答案
从BindingSource文档中: