Solved

Dataview.RowFilter problem - displaying field value  from first row

Posted on 2004-04-06
3
1,488 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
Comment Utility
Here is one way to do it:

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

0
 
LVL 7

Expert Comment

by:ramesh12
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

15 Experts available now in Live!

Get 1:1 Help Now