DataGrid Filter

Oct 31, 2008 at 7:44 PM
Hello,

I am really confused in enabling textbox based search feature in my datagrid.

Here is the declaration of the datagrid:
        <toolkit:DataGrid Name="areaDataGrid"  Margin="10,0,10,0" IsSynchronizedWithCurrentItem="True"
            Grid.Row="1" Height="250" Width="400" SelectionMode="Extended" AutoGenerateColumns="False"
            CanUserReorderColumns="False" GridLinesVisibility="None" AlternationCount="2" CanUserResizeRows="False"
            ItemsSource="{Binding}" >

And this is how I attach the data source (a subsonic collection) to the grid:
            CollectionView dgcv = new CollectionView(areaCollection);
            dgcv.Filter = SearchFilter;

            areaDataGrid.ItemsSource = dgcv;

This is the TextChanged method of the textbox which is being used in the filtering process:
            ((CollectionView)areaDataGrid.ItemsSource).Refresh();

The strange thing is, when I set a breakpoint in the above method (i.e. TextChanged method) and check the ItemsSource, it DOES gets filtered, but the corresponding changes do not reflect in the datagrid. It shows all the items in the datagrid.

I tried adding areaDataGrid.Items.Refresh(); to the above method but to no avail. (I knew it hardly will make any difference).

I also tried to implement the solution which is discussed in this thread:
http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=3793
but could not get the datagrid to filter. The ItemsSource yet again gets filtered, but the datagrid still shows all the items.

Please help.
Thanks & Regards,
Yogesh.


Nov 1, 2008 at 2:22 PM
It might sound strange, but I changed CollectionView to a ListCollectionView and the problem got solved. With ListCollectionView both the ways, my own and the one suggested in the thread http://www.codeplex.com/wpf/Thread/View.aspx?ThreadId=3793 worked.

Is this a bug?

May 31, 2009 at 1:35 PM

please what is areaCollection? im new using wpf. intellisence is not showing me this areaCollection, is it a method i have to create? if yes,

please explain how.

Big Thanks in advance

austin