Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

When I use this code to sort a dataview I can't seem to get hold of the correct row within the dataview?

 

My understanding of this code snippet is sort the dataview by the score column default to ascending. Display the fist rows second column. This should display the lowest score, but it does not?

 

Any ideas? :(

 

dvDataView.Sort = "Score"

MessageBox.Show(dvDataView.Table.Rows(0).Item(1))

My website
  • *Experts*
Posted

When you use the Table property on a DataView, it goes back to the original DataTable. That table does have a Rows property (which you use), but it knows nothing of the DataView. If you use the Rows property of the DataView, you'll get the sorted rows.

 

I assume dvDataView is a new DataView below:

Dim dvDataView As DataView = New DataView(...)
dvDataView.Sort = "Score"
MessageBox.Show(dvDataView.Rows(0).Item(1))

 

If you want the lowest score ONLY, try using the DataTable's Compute method, something like:

dt.Tables(0).Compute("MIN(Score)")

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...