1
votes

I have set the Columns of the DataGridView to SortMode = DataGridViewColumnSortMode.Automatic; But on the click on the cell header, it does not sort it

Deos anyone know how to do it ?

2
Do you have a SortExpression on the column? - Arion
i have just written for every column that column.sortmode = DataGridViewColumnSortMode.Automatic; I dont knw anything about SortExpression - Deepanshu Goyal

2 Answers

1
votes

There is a method Sort in datagridview

dataGridView1.Sort(dataGridView1.Columns["yourcol"],ListSortDirection.Ascending);
0
votes

Your datasource has to be sortable

a DataTable/DataView is sortable

a List is not sortable (by properties) for itself

Have a look here: http://www.codeproject.com/Articles/31418/Implementing-a-Sortable-BindingList-Very-Very-Quic