I am currently writing a .Net web application, making use of SortedBindingList and FilteredBindingList. One issue I have run into is that the FilteredBindingList is matching both partial matches and full matches. This works great when filtering based on user inputs (names, titles etc...), but when filtering on a selection which has an ID associated with it, it matches both the full ID and any ID's that contain partial matches. I have given an example below.
<select id="CustomerName">
<option value="1">Frank</option>
<option value="2">Bert</option>
<option value="11">Jane</option>
</select>
If I was to filter on the 'value' property of the select list, which in this instance is the customers unique identifier. Using a FilteredBindingList selecting Bert or Jane would return only the rows associated with Bert or Jane. Selecting Frank would return rows associated with Frank and Jane as the value of 1 can be matched on both Frank and Jane's record.
My vb.Net code is as follows:
Dim filteredList As New FilteredBingList(Of CustomerOrders)(sortedList)
filteredList.ApplyFilter("CustomerID", CustomerName.SelectedValue)
e.BusinessObject = filteredList
Am I missing a step? As there doesn't appear to be an obvious way to prevent the filter from matching partial hits.
Many thanks for taking the time to read/reply to my issue.
Cheers,
Andy
After a lot of research and googling (my google-fu is weak) I found what I was looking for.
It turns out by default the ApplyFilter for a FilteredBindingList uses Contains, which is why it is returning anything that matches the result. This is easily remedied by specifying a new FilterProvider. See my code below if you need an example.
Protected Sub Customers_SelectObject(Byval sender as Object, ByVal e As Csla.Web.SelectObjectArgs) Handles CustomerDataSource.SelectObject
Dim filteredList As New FilteredBindingList(Of CustomerOrders)(sortedList)
filteredList.FilterProvider = AddressOf CustomFilter
filteredList.ApplyFilter("CustomerID", CustomerName.SelectedValue)
e.BusinessObject = filteredList
End Sub
Private Function CustomFilter(item As Object, filter As Object) As Boolean
Dim result As Boolean = False
If item IsNot Nothing AndAlso filter IsNot Nothing Then
result = CStr(item).Equals(CStr(filter))
End If
Return result
End Function
As you can see the code is very similar and requires very little changing.
Thank you for those that took the time to look over my question.
Cheers,
Andy