Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dataview.RowFilter problem - displaying field value  from first row

Posted on 2004-04-06
3
Medium Priority
?
1,525 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 200 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

971 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