Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a WPF project that draws data from a dataset. In one particular view I have a grid and I want to show a filtered version of the data

I've read that I cant Filter a BindingListView but this is a CollectionViewSource

My code is this:-

Private Sub UserControl_Loaded_1(sender As Object, e As RoutedEventArgs) Handles MyBase.Loaded

 Dim _ds As CantileverDataSet
 Dim _carcasseTableAdapter As CantileverDataSetTableAdapters.MaterialsTableAdapter
 Dim _carcasseViewSource As CollectionViewSource

 _ds = CType(Me.FindResource("CantileverDataSet"), CantileverDataSet)

 _carcasseTableAdapter = New CantileverDataSetTableAdapters.MaterialsTableAdapter
 _carcasseTableAdapter.Fill(_ds.Materials)
 _carcasseViewSource = CType(Me.FindResource("MaterialsViewSource"), CollectionViewSource)

 AddHandler _carcasseViewSource.Filter, AddressOf CarcasseFilter
End Sub

Private Sub CarcasseFilter(ByVal sender As System.Object, ByVal e As FilterEventArgs)
    'Accept everything for now

    e.Accepted = True
End Sub

The error I get is

'System.Windows.Data.BindingListCollectionView' view does not support filtering.

If I do _carcasseViewSource.GetType I get CollectionViewSource If I do _carcasseViewSource.View.GetType I get BindingListCollectionView

It's as if it is treating my _carcasseViewSource as a BindingListCollectionView regardless

Here is the XAML of the grid just in case

    <Grid x:Name="CarcasseGrid" DataContext="{StaticResource MaterialsViewSource}" >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Label Content="Material Code:" Grid.Column="0" Grid.Row="0"/>
        <TextBox x:Name="MaterialCodeTextBox" Grid.Column="1" Grid.Row="0" Text="{Binding MaterialCode, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
        <Label Content="Name:" Grid.Column="0" Grid.Row="1"/>
        <TextBox x:Name="NameTextBox" Grid.Column="1" Grid.Row="1" Text="{Binding Name, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}"/>
    </Grid>

Any thoughts would be greatly appreciated

share|improve this question

1 Answer

you can use IBindingListView.Filter when working with datasets/datatable.

take a look at this for the filter expression

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.