|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Iterate a datatable filtering on the default view.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[i]; } And then, if you need to, access the underlying row through rowView.Row property. -- Show quoteMiha Markic [MVP C#, INETA Country Leader for Slovenia] RightHand .NET consulting & development www.rthand.com Blog: http://cs.rthand.com/blogs/blog_with_righthand/ "Chris" <chris01@newsgroups.nospam> wrote in message news:%23H9PBr6SHHA.3440@TK2MSFTNGP03.phx.gbl... >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 > 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 Show quote "Chris" <chris01@newsgroups.nospam> schreef in bericht news:%23H9PBr6SHHA.3440@TK2MSFTNGP03.phx.gbl... >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 > |
|||||||||||||||||||||||