Guys, is there a way to programatically and more efficiently sort records displayed in a datagridview control? If so, how?

Recommended Answers

All 4 Replies

Guys, is there a way to programatically and more efficiently sort records displayed in a datagridview control? If so, how?

Required: CheckBox and DatagridView
Checboxname = chkboxDesc
DatagridView = DatagridView1

Private Sub chkboxDesc_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkboxDesc.CheckedChanged
        If chkboxDesc.Checked = True Then
            DatagridView1.Sort(DatagridView1.Columns(0), _
              System.ComponentModel.ListSortDirection.Descending)
        ElseIf chkboxDesc.Checked = False Then
            DatagridView1.Sort(DatagridView1.Columns(0), _
             System.ComponentModel.ListSortDirection.Ascending)
        End If
    End Sub

Guys, is there a way to programatically and more efficiently sort records displayed in a datagridview control? If so, how?

Hi,

You should use the Datagridview.Sort method.
You can make your sorting in a ascending or decending direction.

You can find an example, here.

If you are not going to sort your rows at runtime you can also sort them when you retrieve them from the Database

Guys, thank you especially to bLuEmEzzy. This problem has definitely been solved!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.