Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm having problems sorting my dataview. If anyone could help that would be great. here is what i have

 

(dt is my datatable)

 

Dim dv As New DataView(dt, "", "", DataViewRowState.CurrentRows)

dv.Sort = "ClientID"

PrintTable(dv.table, "DataTable") ' using this to test the sort

'then i would like to replace my current datatable with what i just sorted

 

i've also tried just sorting like this

dt.defaultview.sort = "ClientID"

but that still doesn't work.

 

Private Sub PrintTable(ByVal t As DataTable, ByVal label As String)

' This function prints values in the table or DataView.

Console.WriteLine("\n" + label)

Dim row As DataRow

Dim c As DataColumn

For Each row In t.Rows

For Each c In t.Columns

Console.Write("\t{0}", row©)

Next c

System.Console.WriteLine("")

Next row

Console.WriteLine()

End Sub

 

Any ideas where i am going wrong?

Posted

How would i go about doing this?

 

By refering to the table property you are looking at the original unsorted table. If you databind to the dataview that will display sorted data' date=' IIRC programatically you should be looking at the DataView's Item property.[/quote']
  • *Experts*
Posted

Offhand, you'll need a new function PrintDataView that accepts a DataView instead of a DataTable. Then loop through a DataRowView collection instead of the Rows.

 

You might change your PrintTable to be more generic, but since it looks like test code I'd just use two functions.

 

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