Reputation: 4997
I need to sort the datagridview programmatically. I googled a lot but nothing worked for me.
Datagridview is not bound to any datasource. Data is being added manually. My requirement is to sort it as when a 'Sort' button is pressed.
Can anyone suggest me code in vb.net?
Upvotes: 3
Views: 24614
Reputation: 1119
The code above works. You can, of course, choose any valid column. Here it is in C#, the only difference is the square braces []:
gridview.Sort( gridview.Columns[0], System.ComponentModel.ListSortDirection.Ascending );
Upvotes: 0
Reputation: 4487
Try like this
DataGridView1.Columns(0)
-> Give which column you want to sort
System.ComponentModel.ListSortDirection.Ascending
-> Give direction of ascending or decending
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
DataGridView1.Sort(DataGridView1.Columns(0),
System.ComponentModel.ListSortDirection.Ascending)
End Sub
Upvotes: 11