Search code examples
c#winformsdatagridviewsortdirection

DataGridViewColumn initial sort direction


I'm working in VS2008 on a C# WinForms app. By default when clicking on a column header in a DataGridView it sorts that column Ascending, you can then click on the column header again to sort it Descending.

I am trying to reverse this, so the initial click sorts Descending then the second click sorts Ascending and I haven't been able to figure out how to do this. Does anyone know?

Thanks


Solution

  • You can set the HeaderCell SortGlyphDirection to Ascending, and then the next click will give you the descending order. The default is none.

    dataGridView1.Sort(Column1, ListSortDirection.Ascending);
    this.Column1.HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Ascending;