Click here to Skip to main content
13,044,927 members (44,404 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I tested DataView.RowFilter and it works OK when the DataView is obtained from a single DataTable (created by DataTable constructor or filled by an adapter). However it doesn't work for a DataTable obtained from a DataSet (DataSet.Tables[index/TableName]). Could you please tell me how to make it work?

Or if possible, please give me another way to filter rows in a DataTable which is as an element of a DataSet???

Thank you!

Posted 22-Mar-13 5:26am
Updated 22-Mar-13 5:27am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You can take an array of DataRow and use select method from the DataTable.
The code is explained below:

suppose you have a DataTable and let us say you have a column Age, on which you want apply filter,

dt is your DataTable.

DataRows[] drArrRow=dt.Select("Age =" + txtFilter.Text);

lets take another DataTable dtFilter and lets clone it from the dt DataTable

DataTable dtFilter = dt.Clone();

foreach (DataRow d in drArrRow)
dtFilter .ImportRow(d);
dataGridView1.DataSource = dtFilter;
//Re-Bind your DataGridView for the filtered result.

you are done with your filtered result.
supernorb 23-Mar-13 13:05pm
Selecting of course works OK, however that's not what I want, selecting rows may lead to memory and performance problems, filtering is just a different thing. Thanks.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Check this
DataSet ds=getDataSet();
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "ID=12";
DataTable dt = dv.ToTable();
supernorb 23-Mar-13 13:09pm
Of course, that's what I did, I also tried DataSet.DefaultViewManager.DataViewSettings["tableName"].RowFilter = "..." and of course this is likely the same to your solution, can't understand why it doesn't work, except the DataGridView's DataSource is a DataTable, a BindingSource, but in my case, it is a DataSet (and use DataMember to specify what table it's bound to). Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 23 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100