Iterate a datatable filtering on the default view.

  • Thread starter Thread starter Chris
  • Start date Start date
C

Chris

I have a data table for which I have set the default view's rowfilter.
If I bind to a control everything is fine. If I go through the table with a
foreach I see everything, not my filtered data.
How would I iterate through with respect to the rowfilter?


MyDataset.Tables["row"].DefaultView.RowFilter = "region='US'";

foreach (DataRow dr in MyDataset.Tables["row"].Rows)
{
this.lblFilter.Text = lblFilter.Text + " --- " +
dr["region"].ToString();
}

TIA,

Chris
 
You should iterate all DataRowViews, like
for (int i=0; i<MyDataset.Tables["row"].DefaultView.Count; i++)
{
DataRowView rowView = MyDataset.Tables["row"].DefaultView;
}

And then, if you need to, access the underlying row through rowView.Row
property.
 
Hi Chris,

I totally agree with Miha. That method should work.

Additional, we can also use "foreach" statement with it.
foreach (DataRowView drv in in MyDataset.Tables["row"].DefaultView)
{ ... }

Have a great day.
Sincerely.
Wen Yuan
 
Chris,

I agree with Miha and WenYuang, but be aware that you have given your table
the name "row" a little bit strange name for a table. Have a look on it, if
that was what you was meaning?

Cor
 
Hi Chris,

We haven't heard from two days. I just want to check if you have any
further question.
Please fell free to reply me if there is anything we can help with.

Have a great day!
Wen Yuan
 
Back
Top