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
Solved

Dataview.RowFilter problem - displaying field value  from first row

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
InputLanguage 1 33
List<PaisEntity> - show some 1 28
C# Gridview 1 47
How to repeat the data 4 17
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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