Or capture the CellClick event, and check the rowindex in the
DataGridViewCellEventArgs. If it's -1, they clicked on the header.
RobinS,
Thank you. I tried MSDN sample below with Virtual Mode DataGridView.
Issues:
1. Sort glyph is not visible in most columns. It is located too far right.
It is visible only if I make
column very wide. How to force sorh glyph to appear immediately after
column
header text or before header ? Or is it possible to use some other sort
indicator ?
2. Sort(newColumn, direction);
causes exception
operation not supported when grid is in virtual mode. I commented it out
for
testing.
3. If new column is sorted, sort glyph is not removed from old column.
4. Descending sort order glyph is never displayed.
How to fix those issues ?
Andrus.
protected override void
OnColumnHeaderMouseClick(DataGridViewCellMouseEventArgs e) {
DataGridViewColumn newColumn = Columns[e.ColumnIndex];
DataGridViewColumn oldColumn = SortedColumn;
ListSortDirection direction;
// If oldColumn is null, then the DataGridView is not sorted.
if (oldColumn != null) {
// Sort the same column again, reversing the SortOrder.
if (oldColumn == newColumn && SortOrder == SortOrder.Ascending) {
direction = ListSortDirection.Descending;
} else {
// Sort a new column and remove the old SortGlyph.
direction = ListSortDirection.Ascending;
oldColumn.HeaderCell.SortGlyphDirection = SortOrder.None;
}
} else {
direction = ListSortDirection.Ascending;
}
// Sort the selected column.
// this causes exception: operation not supported when grid is in virtual
mode:
//Sort(newColumn, direction);
newColumn.HeaderCell.SortGlyphDirection =
direction == ListSortDirection.Ascending ?
SortOrder.Ascending : SortOrder.Descending;
base.OnColumnHeaderMouseClick(e);
}