Oct 17, 2008 at 9:24 AM
I want to have a grid, above the grid, i want to have a series of textboxes(one for each field/coloumn) and when i type something in the textbox, the corresponding dagatrid column should be searched/filterd.

is it possible to search the columns for value?
Oct 20, 2008 at 12:37 AM
DataGrid derives from ItemsControl so filtering will be similar to other ItemsControls like ListView.  Josh Smith has this nice article,, on a PropertyFilterGroupView control that can do some cool things with filtering and using on an ItemsControl.  In his example he uses a ListView but you can just as well use it with a DataGrid.
Oct 20, 2008 at 10:17 PM
Here is an example that uses the TextChanged event on a TextBox to trigger filtering in the DataGrid to give you "search as you type" functionality. The performance of this will be worse as the number of items increases so keep that in mind.


<TextBox x:Name="mSearchBox" TextChanged="mSearchBox_TextChanged" />
<dg:DataGrid x:Name="mUsersDataGrid" ItemsSource="{Binding Users}" >...</dg:DataGrid>

Code Behind (C#):

        private void mSearchBox_TextChanged(object sender, TextChangedEventArgs e)
            ICollectionView view = CollectionViewSource.GetDefaultView(mUsersDataGrid.ItemsSource);
            view.Filter = SearchFilter;

        public bool SearchFilter(object item)
            string searchText = mSearchBox.Text;
            if (!string.IsNullOrEmpty(searchText))
                var user = item as User;
                if (user == null || !user.Name.ToUpper().Contains(searchText.ToUpper()))
                    return false;
            return true;