在 DataGridView 中排序时等待光标
我正在使用标准的.Net 2.0 DataGridView,列上的排序模式为自动。 它非常非常慢(这可能是关于如何加快速度的另一个问题),但我似乎找不到在执行排序操作时维护 WaitCursor 的事件或事件组合。
有想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
挂钩“MouseDown”事件,用“HitTest”方法检查用户点击的位置。 如果用户单击列标题,则设置“Cursor.Current = Cursors.Wait”并将某些标志“isSorting”设置为 true。
挂钩“MouseUp”事件,检查“isSorting”标志是否为true,然后设置“Cursor.Current = Cursors.Default”。
编辑:
使用“Sorted”事件而不是“MouseUp”。
“MouseUp”是功能性的,但“Sorted”是“更干净”的解决方案。
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.
《纪元 2021》,死灵术是最好的:)我仍在寻找一种方法来正确地做到这一点。
我尝试过的方法和无效的方法
当用户开始拖动(重新排序列标题)时,也会触发
CellMouseDown
事件。 所以这是一个妥协。CellMouseClick
事件在Sorted
事件之后触发。 由于线程在排序操作期间被占用并且没有真正的SortStart
事件,我开始认为这是不可能的。我最终做了什么
如果您使用
DataTable
作为 gridview 的数据源,则必须禁用每列的自动排序。你也许可以这样做
我最终使用
CellMouseDown
事件、CellMouseUp
事件和两个变量mouseDownColumnIndex
和sortExpression
作为先前排序的句柄行动。这似乎比默认的“自动”排序更快。
Anno 2021, necromancy at it's best :) I was still looking for a way to do this correctly.
What I tried and what didn't work
The
CellMouseDown
event is also fired when a user starts dragging (reordering column headers). So that's a compromise.The
CellMouseClick
event is fired AFTER theSorted
event. Since the thread is occupied during the sorting operation and there is no trueSortStart
event, I was starting to think it would be impossible.What I ended up doing
If you're using a
DataTable
as a datasource for your gridview, you'll have to disable automatic sorting for each column.You might be able to do this with
I ended up using the
CellMouseDown
event, theCellMouseUp
event and two variablesmouseDownColumnIndex
andsortExpression
as handles on previous sorting actions.This appears to be faster than default "automatic" sorting.