Get the SourceControl of my ContextMenuStrip when I use the shortcut key

六月ゝ 毕业季﹏ 提交于 2019-12-06 03:40:13

The SourceControl property shows the control that caused the ContextMenuStrip to open. Since in this case the ContextMenuStrip doesn't display there is no control used to open it, and thus the property is null.

This property is better used in the context of the opening event. See ContextMenuStrip.SourceControl.

Update: One method to figure out which DataGridView was the intended receiver of the ToolStripMenuItem click would be to see which one has the focus:

var dgv = this.ActiveControl as DataGridView;
if ( dgv != null) // make sure to check for null before trying to use this var
    //...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!