CSLA 4.2.x FilteredBindingList

CSLA 4.2.x FilteredBindingList

Old forum URL: forums.lhotka.net/forums/t/11607.aspx


gajit posted on Friday, September 28, 2012

Does anyone have an example of how I could implement an ApplyFilter method for FilteredBindingList other than the standard one which uses the "contains" logic.

I'd actually like to subclass FBL to have a number of different filter operators, but I'm complete unfamiliar with the C# code that this version is created with.

Would I be correct in thinking that the actual code that does the comparing is the method "Filter" in the DefaultFilter class?

How would I go about implementing a custom filter?

Any help would be appreciated.

 

Thanks,

Graham

 

 

 

 

gajit replied on Friday, September 28, 2012

never mind. I figured it out.

I created a "CustomFilters" class, and created a number of methods, e.g.

    Public Shared Function DateGEFilter(ByVal item As Object, ByVal filterValue As Object) As Boolean

        Dim columnvalue As String = item.ToString

        ' assume filter is an array of string
        Dim value As String = CType(filterValue, String)
        If CType(columnvalue, DateTime) >= CType(value, DateTime) Then
            ' found a match
            Return True
        End If
        ' didn't find a match
        Return False

    End Function

Called from my app. like so -

                 Dim fLIST As New Csla.FilteredBindingList(Of ContractInfo)(list)

                fLIST.FilterProvider = AddressOf CustomFilters.DateGEFilter
                fLIST.ApplyFilter("DeliveryDate", dtpFROM.Value)

                fLIST = New Csla.FilteredBindingList(Of ContractInfo)(fLIST)
                fLIST.FilterProvider = AddressOf CustomFilters.DateLEFilter
                fLIST.ApplyFilter("DeliveryDate", dtpTO.Value)

 

Woohoo! works great!

Big Smile

Graham

 

Copyright (c) Marimer LLC