FilteredBindingList : Multiple ApplyFilter() Is this an issue ?

FilteredBindingList : Multiple ApplyFilter() Is this an issue ?

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


Jabadoo posted on Friday, February 02, 2007

I would expect the ApplyFilter() to act as an AND operator when doing it multiple times?

for example :

_filteredList.ApplyFilter("field1",value1);

_filteredList.ApplyFilter('field2", value2);

resulting in (field1=value1 AND field2=value2)

This works when the first ApplyFilter has results.

But, in my case, when the first ApplyFilter has zero results, the second one could have results.

I guess this is a bug in the FilteredBindingList ?

As a workaround, I need to count the previous results, and only do the second ApplyFilter when the first has zero results.

fsjohn replied on Friday, December 07, 2007

same to me

fsjohn replied on Friday, December 07, 2007

same to me

JoeFallon1 replied on Friday, December 07, 2007

Offhand, I would say you are doing it wrong.

You should set up your filter once and then call it.

Something like this:

Protected Function GetDataSource(ByVal key As Long) As FilteredBindingList(Of SomeBO)
 
Dim filteredList As FilteredBindingList(Of SomeBO)
 
Dim filterValue As Object
 
filteredList = New FilteredBindingList(Of SomeBO)(mSomeColl)

  If filteredList IsNot Nothing Then
   
filteredList.FilterProvider = AddressOf MyFilter
    filterValue = key
    filteredList.ApplyFilter(
"", filterValue)
 
End If

 
Return filteredList

End Function

'The primary requirement is that the method signature conform to the FilterProvider delegate. The method must 'return True for items that should be included in the filtered view, and False for those that should not.

Public Shared Function MyFilter(ByVal item As Object, ByVal filterValue As Object) As Boolean
'You need to implement code here to check the value of the item parameter based on your rules,
'along with any criteria provided through the filterValue parameter.
'Remember that the item parameter could be the value of a specific property, or it could be a reference to the actual business object.
'And keep in mind that the filterValue parameter is of type Object, and so it could be any value you’d like, even a complex object.

  Dim result As Boolean = False

  If item IsNot Nothing AndAlso filterValue IsNot Nothing Then
   
Dim obj As SomeBO = DirectCast(item, SomeBO)
    ' Here is where you can compare multiple properties if you want:
    result = (obj.Key =
CLng(filterValue))
 
End If

  Return result

End Function

Joe

fsjohn replied on Monday, December 10, 2007

I solved filtering the previous filtered collection:

_filteredList.ApplyFilter("field1",value1);
_filteredList = New Csla.FilteredBindingList(Of yourBO)(_filteredList)
_filteredList.ApplyFilter('field2", value2);



fs

RockfordLhotka replied on Monday, December 10, 2007

The current behavior is by design. If you want to filter on multiple columns I recommend creating a custom filter provider.

McManus replied on Monday, December 10, 2007

RockfordLhotka:
The current behavior is by design. If you want to filter on multiple columns I recommend creating a custom filter provider.

Another option is to use the ObjectListView, which can be found in CSLAContrib

Cheers,
Herman

Copyright (c) Marimer LLC