datagridview-如何确定mouseclick事件是否来自单击列标题 [英] datagridview - how to determine if a mouseclick event came from clicking a column heading

查看:92
本文介绍了datagridview-如何确定mouseclick事件是否来自单击列标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个datagridview控件,具有SelectionMode = FullRowSelect.此控件还允许单击任何列标题以对任何列进行排序.单击列标题时,将在此控件上触发MouseClick事件,除了datagridview排序外,这导致我的代码的行为类似于再次单击了最后单击的行(焦点"所在的位置).我想区分在网格内发生的MouseClick和在单击列标题时发生的MouseClick.无法弄清楚.我确实添加了ColumnHeaderMouseClick事件,该事件在单击列标题时会在MouseClick事件之外触发,但会在MouseClick事件之后触发(如果在事件触发之前触发,那么我这里有一种解决方法).关于如何确定MouseClick是否在列标题上,或者如何使ColumnHeaderMouseClick首先触发的任何建议?任何帮助是极大的赞赏.谢谢.

I have a datagridview control, with SelectionMode=FullRowSelect. This control also allows any column heading to be clicked to sort any column. The MouseClick event fires on this control when a column heading is clicked, which results in my code acting like the last row that was clicked (where ''focus'' was) is clicked again, in addition to the datagridview sorting. I want to distinguish between a MouseClick that happens within the grid, and a MouseClick that happens when a column heading is clicked. Can''t figure it out. I did add a ColumnHeaderMouseClick event, which does fire in addition to the MouseClick event when a column heading is clicked, but it fires after the MouseClick event (if it would fire before, then I''d have a workaround here). Any suggestions on how to determine if a MouseClick was on a column heading, or how to get the ColumnHeaderMouseClick to fire first? Any help is greatly appreciated. Thanks.

推荐答案

您可以使用 ^ ]事件或 CellClick [ ^ ]事件,您可以使用这两个事件来表示何时单击单元格.无论如何,我不会使用MouseClick事件,因为如果用户双击,则会触发MouseDoubleClick事件.
You can use the CellMouseClick[^] event or CellClick[^] event, either of which you could use to signal when a cell is clicked. I wouldn''t use the MouseClick event anyway because if the user double clicks, the MouseDoubleClick event is fired instead.


我发现,如果我使用cellclick事件,那将允许我检查e.RowIndex,这是mouseclick事件中不可用的值.然后,我可以检查它是否= -1,它标识列标题.问题已解决-谢谢.
What I found was that if I used the cellclick event, that allowed me to check e.RowIndex, which is a value not available in the mouseclick event. Then I can check if it = -1, which identifies a column heading. Problem solved - thanks.


这篇关于datagridview-如何确定mouseclick事件是否来自单击列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆