【问题标题】:Filter on bindingSource for a datagridview doesn't work过滤 datagridview 的 bindingSource 不起作用
【发布时间】:2012-08-11 00:39:23
【问题描述】:

我有 5 个数据网格视图,每个有 5 到 15 列...

所以我正在尝试使过滤自动化一点。但我根本无法让它工作!

我的 bindingSource 使用了实现 Sortable 的 BindingList :http://www.tech.windowsapplication1.com/content/sortable-binding-list-custom-data-objects

我已经搜索了一段时间,但我找不到为什么我可以设置 bindingSource.Filter,但它没有做任何事情:S

我找到了数据表或 c# 的示例,但我还没有找到 Vb.net 和 BindingSource 的示例...

这是我创建绑定源的代码,我添加了过滤器作为测试,它通常不在这里。

Public Function reqTable(Of T)(ByVal pTable As String, ByVal pNoProjet As Integer, 
      Optional ByVal strAdditionnalConditions As String = "") As BindingSource
    Dim lstRetour As New cclSortableBindingList(Of T)(New List(Of T))
    Dim bsRetour As New BindingSource(lstRetour, "")

    rsRequestCSV = conSQL.Execute("SELECT * FROM " & pTable & " WHERE NoProjet = " & 
        pNoProjet & " " & strAdditionnalConditions)
    With rsRequestCSV
        While Not .EOF
            lstRetour.Add(Activator.CreateInstance(GetType(T), New Object() 
                 {rsRequestCSV.Fields})) 'New clsTable(rsRequestCSV.Fields))
            .MoveNext()
        End While
    End With
    bsRetour.Filter = "Quantite < 3"
    Return bsRetour
End Function

【问题讨论】:

    标签: vb.net datagridview filter bindingsource


    【解决方案1】:

    为了使用BindingSource.Filter,底层列表(cclSortableBindingList)需要实现IBindingListView接口。 BindingList 没有实现这个接口。

    请参阅来自 MSDN 的 BindingSource.Filter Property

    【讨论】:

    • 是的,我已经猜到了,但是我真的不想自己在 BindingList 上实现 IBindingListView,必须在已经完成的地方有代码:S 或者真的,只是一个坏使用绑定列表的想法?因为大部分代码都在那里(我已经为大约 6 个表创建了 Modele 类:S),我不想使用 dataTableCollection 重新开始:S
    • 我尝试在我已经实现 ISortable 的类之上实现 IBindingListView,但至少我无法轻松实现,所以我切换到 DataSet / DataTables,现在工作正常,排序,过滤等......
    猜你喜欢
    • 1970-01-01
    • 2018-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-22
    相关资源
    最近更新 更多