Sort datagrid

henrik79

New member
Joined
Feb 7, 2006
Messages
3
Programming Experience
1-3
Hi!

I have this code for populating a datagrid:

Dsmyrecs = New InTheHand.Data.Adoce.AdoceDataAdapter("tbl_OBJ", cnDataFile)
' Dim ds As New DataSet("Tables")
myds = New DataSet("Tables")

Dsmyrecs.Fill(myds, "tbl_OBJ")
DataGrid1.DataSource = myds.Tables(0)

My question is: How do I sort the datagrid on a certain field?
 
You need to use a data view.

Dim ordertbl As New DataTable = myds.tables(0)

Dim myview As New DataView
myview = ordertbl .DefaultView
myview.Sort = "ID DESC"

dgOrders.DataSource = myview
 
Hi,

I have some problems with sort. I need to order by Date, but I don't know why, that does not work to me. The order is wrong.

Someone can guide me through this?

Thanks in advance,
Gorita
 
I have the solution (^^).

This is the example:

Dim dt As New DataTable
Dim dr As DataRow

dt.Columns.Add("Rem", GetType(String))
dt.Columns.Add("Date", GetType(Date))
dt.Columns.Add("Priority", GetType(String))
dt.Columns.Add("Message", GetType(String))

For i as integer = 0 to 10
dr = dt.NewRow()
dr("Rem") = "Rem" & i
dr("Date") = Convert.toDate(i&"/"&i+1&"/2008")
dr("Priority") = "Low"
dr("Message") = "Message " & i
dt.Rows.Add(dr)
Next

Dim view As DataView = dt.DefaultView
view.Sort = "Date DESC"
dgv.DataSource = dt

I hope it helps.

Thank you!
 
Back
Top