开发者

Effectively highlighting column and row on a DataGridView as mouse moves

I am trying to highlight the row and column which the mouse is on. Essentially this means to change the background color of all the appropriate cells. Currently I am tryi开发者_运维技巧ng to do this in the MouseMove event. However, this is causing slow performance.

I was suggested to use WPF for better performance, however I do not wish to go that route. What are some ways in which I can improve performance within C#?


Try the CellMouseEnter event; it fires only once each time the mouse moves over a new cell, unlike MouseMove, and it doesn't require clicking on the cell to fire the event. You should probably handle the CellMouseEnter (for highlighting the new cell), CellMouseLeave(for un-highlighting the old cell) and possibly the Leave event of the entire DGV (to make sure all cells are unhighlighted).


You can use DataGridView.RowEnter Event which occurs only when a new row becomes active. The msdn links shows exactly the same sample you are trying to accomplish.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜