的ContextMenuStrip的SourceControl是ToolStripMenuItem没有点击? [英] SourceControl of ContextMenuStrip is Nothing in ToolStripMenuItem Click?

查看:482
本文介绍了的ContextMenuStrip的SourceControl是ToolStripMenuItem没有点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ContextMenuStrip 连接到更多的控制。

I have single ContextMenuStrip attached to more controls.

在使用打开事件的ContextMenuStrip 的过滤/禁用某些方面的条目。 在这种情况下,物业 ContexteMenuStrip.SourceControl 设置是否正确。

In use the Opening event of ContextMenuStrip to filter/disable some context entries. In this case the property ContexteMenuStrip.SourceControl is set correctly.

我的问题是一个 ToolStripMenuItem 的Click事件。本项目是一个 ToolStripDropDown 里面。

The problem I have is on the Click event of a ToolStripMenuItem. This item is inside a ToolStripDropDown.

我得到code中的父项:

I get the parent item with code:

Dim tsmi As ToolStripMenuItem = DirectCast(DirectCast(DirectCast(sender, ToolStripMenuItem).Owner, ToolStripDropDown).OwnerItem, ToolStripMenuItem)

然后,我得到的ContextMenuStrip:

then I get the ContextMenuStrip:

Dim contextMenu As ContextMenuStrip = DirectCast(tsmi.Owner, ContextMenuStrip)

但现在,如果我检查 contextMenu.SourceControl 没有

你有什么想法什么是错的,或者为什么SourceControl没有在这种情况下设置?

Do you have any idea what is wrong or why SourceControl is not set in this case?

感谢你在前进

推荐答案

我找到了一个解决办法,是不是真正的问题的答案。所以我会离开它打开一会儿。

I found a workaround that is not really the answer to the question. So I will leave it open for a while.

我用的ContextMenuStrip 打开事件存储在本地源对象。

I used the ContextMenuStrip Opening event to store locally the source object.

Private Sub contextGrid_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles contextGrid.Opening

  _ContextSourceGrid = DirectCast(contextGrid.SourceControl, DataGridView)

End Sub

和直接引用里面所有保存的对象 ToolStripMenuItem 点击事件。

and refer directly to the saved object inside all ToolStripMenuItem Click events.

这篇关于的ContextMenuStrip的SourceControl是ToolStripMenuItem没有点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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