如何在VB.NET中的CollectionView上使用多个过滤器

时间:2011-11-06 00:31:20

标签: wpf filter collectionviewsource

我正在尝试在CollectionView上使用多个过滤器 - 使用此方法:http://bea.stollnitz.com/blog/?p=32

我已经找到了将过滤器添加到CollectionView

的语法

我现在想知道如何在Filter方法中添加其他参数。

e.g。

Public Shared Sub FilterByAge(ByVal Item As Object, ByVal e As FilterEventArgs, ByVal Age As Int32)
    '
    '
    Dim PersonToFilter As Person = TryCast(e.Item, Person)
    '
    '
    If Not PersonToFilter.Age = Age Then
        '
        e.Accepted = False
        '
    End If
    '
    '
End Sub

使用Deletegate可以做到这一点吗?我不是很熟悉他们:

有人能指出我在VB.NET中使用额外的过滤器参数添加多个CollectionViewSource过滤器的正确方向吗?

由于 本

1 个答案:

答案 0 :(得分:2)

  

我现在想知道如何在Filter方法中添加其他参数。

您不能这样做,处理程序签名必须与事件签名匹配。最简单的解决方案是将年龄存储在字段中并在处理程序中使用该字段:

Private _age As Int32

Public Sub FilterByAge(ByVal Item As Object, ByVal e As FilterEventArgs)
    '
    '
    Dim PersonToFilter As Person = TryCast(e.Item, Person)
    '
    '
    If Not PersonToFilter.Age = _age Then
        '
        e.Accepted = False
        '
    End If
    '
    '
End Sub