Skip to main content Skip to footer

FullTextSearch In C1DataGrid Bound To DataTable

C1DataGrid provides a very useful feature - FullTextSearch, which allows user to search all the columns at the same time. This functionality can be enabled by setting the attached 'FullTextSearchBehavior' property. Now this feature works fine when binding to a native collection because the functionality creates a custom collection view on the bound collection for enabling custom filters. However, when C1DataGrid is bound to a DataTable (native .NET DataTable or C1.Silverlight.Data.DataTable), full text filtering does not work because there is no collection to create a custom collection view. Lets see how we can enable full text filtering in this case. The solution is to simply apply the RowFilter to the bound DataView when the text in the 'filter box' is changed. Lets say you have a DataTable with three columns (Name, Age, Country), the following RowFilter will filter the data on the basis of the string entered:-

private void Search(object sender, TextChangedEventArgs e)  
 string fs=searchBox.Text;  
 dt.DefaultView.RowFilter = String.Format("Name Like '%{0}%' OR Age Like '%{1}%' OR Country Like '%{2}%'", fs, fs, fs);  

This solution works well both in WPF/Silverlight. Attached is a small Silverlight application with complete implementation. Download C# Sample [SL] Download VB Sample [WPF]


comments powered by Disqus