获取 ContextMenuStrip 中 ToolstripItem 的文本
我有一个 DGV 的上下文菜单条。它有一个名为“ChangeTo”的工具条项目,它分支为一组根据所使用的配置文件动态创建的项目。当我运行具有 Rt-Click 的程序时 ->更改为 -> (项目列表)
当我单击 contextmenustrip 中下拉列表中的任何项目时,我希望 DGV 的选定行更改为列表中的文本...
为此,我需要获取与关联的“文本”工具条项。我该怎么做? 我不能只使用 toolstripitemname.text 因为直到运行时我才知道项目名称...我尝试使用
ChangeTotoolstripitem.DropDown.Items...
但我需要索引...
这是单击项目时我使用的功能
private void changeTypeToToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
I have a contextmenustrip for a DGV. It has a toolstripitem called "ChangeTo" and this branches out into a set of items that are created dynamically based on the config file used. When I run the program that Has Rt-Click -> Change To -> (List of Items)
When I click any item from the drop down list in the contextmenustrip , I want the selected row of the DGV to change to the text in the list...
For this i need to get the 'Text' associated with the toolstripitem. How can i do this?
I cant just use toolstripitemname.text coz i wouldnt know the item name until runtime... I tried using
ChangeTotoolstripitem.DropDown.Items...
but i need the index...
This is the function i use when the item is clicked
private void changeTypeToToolStripMenuItem_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当您拥有 ToolStripItemClickedEventArgs 时,这不会起作用吗?:
Will this not work as you have the ToolStripItemClickedEventArgs?:
使用
use
我不得不读几次这篇文章,但我认为这就是你所追求的:
这就是你所追求的吗?您可以轻松获取控件的名称 (
mi.Name
) 或其他任何名称。I had to read this a few times, but I think this is what you are after:
Is that what you are after? You could just as easily get the control's name (
mi.Name
) or whatever else.