Solved

Dataview.RowFilter problem - displaying field value  from first row

Posted on 2004-04-06
3
1,501 Views
Last Modified: 2012-05-04

When I use the dataview.rowfilter and I try to display the field value of
the first row, the code doesn't seem to show the first row AFTER the
rowfilter (it displays the value of the first row of the dataview without the filter).
This is my code:

DataView DataView_Filter = new DataView();
DataView_Filter.Table = DS_States.Tables["Table1"];
sFilter = "Emplcode = '123233'";
DataView_Filter.RowFilter = sFilter;
MessageBox.Show (DataView_Filter.Count.ToString());    //it displays 6 items, which is correct.

MessageBox.Show (DataView_Filter.Table.Rows[0]["Emplcode"].ToString());
//it displays the first item of the initial dataview, not the filtered dataview

How can I display the first item of the filtered dataview? I assume there
must be some method that returns the array index since Rows[0] is not
necessarily the first row of the filtered dataview.

Thanks,
Vaughn

0
Comment
Question by:MyersA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
PastorDwayne earned 50 total points
ID: 10769687
Here is one way to do it:

MessageBox.Show(( (DataRowView) (DataView_Filter)[0]).Row[0].ToString());

0
 
LVL 7

Expert Comment

by:ramesh12
ID: 10772167
Do not use DataView_Filter.Table as it again gets the data from the original table.

After using filter you should only work with the dataview.
0
 
LVL 2

Author Comment

by:MyersA
ID: 10775243
But what's the difference between:

MessageBox.Show (DataView_Filter.Table.Rows[0]["Emplcode"].ToString());

and

MessageBox.Show(( (DataRowView) (DataView_Filter)[0]).Row[0].ToString());  ?

I ended up using an IENumerator to go through the resulting dataview but it seems that PastorDwayne's way is easier. Plus, I don't have to add something that rhymes with Terminator.
I know how many rows are in the resulting view so I can just go through it with a loop.

Vaughn
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question