Peter17
Peter17

Reputation: 3102

Sorting rows in DataGridView by clicking on the Header column

How to allow sorting rows in the DataGridView by clicking on the Column Header.

Upvotes: 1

Views: 10556

Answers (3)

Csujo
Csujo

Reputation: 507

This is an MSDN link that describes the DataGridViewColumn's SortMode property.

But the DataGridView can't sort any collection automatically (like List). If you want to support sorting and searching on the collection, you have to derive a class from BindingList and override a few base class methods and properties.

Upvotes: 2

test
test

Reputation: 1

Private Sub GridSupplierHelp_ColumnHeaderMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles GridSupplierHelp.ColumnHeaderMouseClick
    GridSupplierHelp.Columns(e.ColumnIndex).SortMode = DataGridViewColumnSortMode.Automatic
End Sub

Upvotes: -1

Peter K John
Peter K John

Reputation: 101

You Could use this in each columns or specified columns to sort the rowsthis->dataGridView1->Columns[n]->SortMode = DataGridViewColumnSortMode::Automatic;

Upvotes: 3

Related Questions