feralin
feralin

Reputation: 3408

Autosorting of Winforms DataGridView

In Winforms, even if a DataGridView is sortable (the user can click a column header to have the rows sorted according to that column's values), when I programmatically add a row using

datagridview.Rows.Add(field1, field2, field3);

the new row is always put at the bottom rather than automatically being placed where it should be according to the current sort column and direction.

How can I put a new row in the datagridview so that it is where it should be according to the current sort settings?

Upvotes: 0

Views: 78

Answers (1)

Transcendent
Transcendent

Reputation: 5745

After you add the new row again to the data grid view, you can call the sort method to programmaticly sort the table:

DataGridViewColumn C = DataGridView1.Columns["Some Column"];
DataGridView1.Sort(C, ListSortDirection.Descending);

Upvotes: 1

Related Questions