views:

501

answers:

1

I am using the standard .Net 2.0 DataGridView with sort mode of automatic on the column. It is very very slow (which should probably be another question on how to speed it up) but I can't seem to find an event or combination of events that will maintain a WaitCursor while this sort operation is being performed.

Ideas?

+4  A: 

Hook "MouseDown" event, check with "HitTest" method where user clicked. If user clicked on the column header set "Cursor.Current = Cursors.Wait" and set some flag "isSorting" to true.

Hook "MouseUp" event, check if "isSorting" flag true, then set "Cursor.Current = Cursors.Default".

EDIT: Use "Sorted" event instead of "MouseUp". The "MouseUp" is funtionaly, but the "Sorted" is "cleaner" solution.

TcKs
I think that MouseUp event would probably occur long before sorting is complete, if is it really slow...
Mr. Brownstone
Yes the mouse up will be completely done before the sort is done.
Greg J
That's what I get for assuming. I just tried it and the mouseup event is not fired until the sort is actually finished. Well done!
Greg J
@Mr. Brownstone - It shouldnt.The sorting is proceed in UI thread, so the "mouse up" message from windows is proceeded after the sorting done.
TcKs