Filter a wpf collectionviewsource in VB?
- by Johnny Westlake
Hi, I want to filter a collectionviewsource using a filter I've written, but I'm not sure how I can apply the filter to it?
Here is my collection view source:
<Grid.Resources>
<CollectionViewSource x:Key="myCollectionView"
Source="{Binding Path=Query4, Source={x:Static Application.Current}}">
<CollectionViewSource.SortDescriptions>
<scm:SortDescription PropertyName="ContactID"
Direction="Descending"/>
</CollectionViewSource.SortDescriptions>
</CollectionViewSource>
</Grid.Resources>
I have implemented a filter as such:
Private Sub WorkerFilter(ByVal sender As Object, ByVal e As FilterEventArgs)
Dim value As Object = CType(e.Item, System.Data.DataRow)("StaffSection")
If (Not value Is Nothing) And (Not value Is DBNull.Value) Then
If (value = "Builder") Or (value = "Office Staff") Then
e.Accepted = True
Else
e.Accepted = False
End If
End If
End Sub
So how can I get the CollectionViewSource filtered by the filter on load? Could you please give all hte code I need (only a few lines I figure) as I'm quite new to coding.
Thanks guys
EDIT: For the record,
<CollectionViewSource x:Key="myCollectionView" Filter="WorkerFilter" ... />
gives me the error:
Failed object initialization
(ISupportInitialize.EndInit).
'System.Windows.Data.BindingListCollectionView'
view does not support filtering.
Error at object 'myCollectionView'