How-To use FilteredBindingList?

How-To use FilteredBindingList?

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


brembot posted on Wednesday, November 22, 2006

Hi All,

I have a EditableRootList and ReadOnlyList collection.I want to filter some data in my collection. How am i going to do this and make it work. I've searched all the forums and was not able to find a concrete example. For example i have a collection of students and i want to filter by surename.

Here's what i did:

...
Private mStudents As Students = Students.GetStudents()
Private mFiltered As Csla.FilteredBindingList(Of
Students) (mStudents)

mFiltered.ApplyFilter("SureName", "Doe")
...


After executing this command i got errors "Unable to cast object of type 'POS.
Students ' to type 'System.Collections.Generic.IList`1[POS.Students ]'."

Am i missing something in my code?

Thanks,
Marlon


xal replied on Wednesday, November 22, 2006

The filtered binding list (like the sorted binding list) take the type of the item, not the list. So if your list contains items of type Student, just change it to:
Private mFiltered As Csla.FilteredBindingList(Of Student) (mStudents).

Also, you need to pass a delegate that does the filtering. Something like:


Public Shared Function Filter(ByVal item As Object, ByVal filterValue As Object) As Boolean
        Dim result As Boolean = False
        If Not item Is Nothing AndAlso Not filterValue Is Nothing Then
            result = DirectCast(item, Student).Surname.Equals(filterValue)
        End If
        Return result
End Function

And then do this with the list:
mFiltered.FilterProvider = AddressOf Filter



Andrés

gajit replied on Thursday, December 07, 2006

xal:
The filtered binding list (like the sorted binding list) take the type of the item, not the list. So if your list contains items of type Student, just change it to:
Private mFiltered As Csla.FilteredBindingList(Of Student) (mStudents).

Also, you need to pass a delegate that does the filtering. Something like:


Public Shared Function Filter(ByVal item As Object, ByVal filterValue As Object) As Boolean
        Dim result As Boolean = False
        If Not item Is Nothing AndAlso Not filterValue Is Nothing Then
            result = DirectCast(item, Student).Surname.Equals(filterValue)
        End If
        Return result
End Function

And then do this with the list:
mFiltered.FilterProvider = AddressOf Filter



Andrés

 

I wonder if I might resurrect this thread briefly.

I'm having problems implemeting the filter also.

When I apply a string value to a column using the .ApplyFIlter method, I get a 'like' filter as opposed to an 'equals' filter.

So, I am trying to implement this methodology, but I am confused... WHERE is the Filter() subroutine implemented? If in the UI, then how do I pass a filter value to the object?

I can't ssee how or where you pass a value to the Filter() Method.

 

Dim FilteredList As New Csla.FilteredBindingList(Of ProspectInfo)(list)

FilteredList.FilterProvider = AddressOf Filter ' <---how do I implement THIS code??

If Len(cboTeam.Text) > 0 Then

   FilteredList.ApplyFilter("SALESREP", cboTeam.SelectedValue.ToString)

End If

I'd very much appreciate your assistance,

Thanks,

G.

Copyright (c) Marimer LLC