Solved

Dataview.RowFilter problem - displaying field value  from first row

Posted on 2004-04-06
3
1,491 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now