Capture the ColumnHeaderMouseClick event.
Or capture the CellClick event, and check the rowindex in the
DataGridViewCellEventArgs. If it's -1, they clicked on the header.
RobinS.
GoldMail, Inc.
-------------------------------
>> Otherwise, you can try handling the sort stuff yourself. You could try
>> capturing the column header click event, check to see what column it is,
[quoted text clipped - 4 lines]
>
> Andrus.
> 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);
}
RobinS - 24 Feb 2008 18:33 GMT
I haven't worked with virtual DGV's. My guess would be that to sort one, you
would have to sort the underlying data source. Are you binding to a
BindingSource, and have you tried sorting using that rather than sorting the
grid itself?
RobinS.
GoldMail, Inc.
-------------------------------
>> Or capture the CellClick event, and check the rowindex in the
>> DataGridViewCellEventArgs. If it's -1, they clicked on the header.
[quoted text clipped - 58 lines]
> base.OnColumnHeaderMouseClick(e);
> }
Andrus - 24 Feb 2008 23:30 GMT
>I haven't worked with virtual DGV's.
How about the sort hlyph display issues ?
I think they apper in normal dgv also.
> My guess would be that to sort one, you would have to sort the underlying
> data source. Are you binding to a BindingSource, and have you tried
> sorting using that rather than sorting the grid itself?
It is not possible to use binding in VirtualMode.
ORDER BY clause of base query must generated dynamically in this case.
I'm looking for such sample.
Andrus.
RobinS - 25 Feb 2008 00:39 GMT
> >I haven't worked with virtual DGV's.
>
[quoted text clipped - 10 lines]
>
> Andrus.
I haven't had any problems with the sort glyph in my DGVs that are bound to
either datasets or customer business objects.
You really might want to check out the data binding book by Brian Noyes; he
does discuss virtual DGV mode in that book.
Also, have you seen the DataGridView FAQ? Try googling for that; it's a 70+
page document that I found helpful.
RobinS.
GoldMail, Inc.