Dataview.RowFilter problem - displaying field value from first row

J

Jim Heimer

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.
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.

Jim
 
J

Jeffrey Tan[MSFT]

Hi Jim,

Based on my understanding, you want to do the row filter through dataview
for your datatable.

After view your code, I find that your filter is correct, but you get the
filtered rows in an in-correct way.

After setting the RowFilter for DataView, you use DataView.Table property
to get the rows. If you view in MSDN, you will see that DataView.Table
property gets the source DataTable, which has nothing to do with filter(You
only filter the dataview not the underlying datatable). So you will get the
source datatable's first row.

Actually, you should do like this:

DataView dv_filter=new DataView();
dv_filter.Table=ds.Tables[0];
dv_filter.RowFilter ="Emplcode = '123233'";
MessageBox.Show(dv_filter[0].Row["Emplcode"]);

================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Jim,

Have you tried my suggestion? Is your problem resolved?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
K

kashif456

Hi,
I am having this similiar problem and I tried the approach that you
mentioned but it didn't work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top