private void DataTable_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
DataGridViewColumn SelectedCol = DataTable.Columns[e.ColumnIndex];
// Sort the same column again, reversing the SortOrder.
if (SortedCol == SelectedCol)
{
SortDir = (SortDir == ListSortDirection.Ascending)
? ListSortDirection.Descending
: ListSortDirection.Ascending;
}
else
{
// Sort a new column and remove the old SortGlyph.
SortDir = ListSortDirection.Ascending;
SortedCol.HeaderCell.SortGlyphDirection = SortOrder.None;
SortedCol = SelectedCol;
}
// Set new Sort Glyph Direction
SortedCol.HeaderCell.SortGlyphDirection = ((SortDir == ListSortDirection.Ascending)
? SortOrder.Ascending
: SortOrder.Descending);
// Build new List with database sort!
BuildList();
}