您好,我有一个带有“收藏夹”菜单的 ToolStripMenu,我想在运行时在 WinForms 应用程序中添加子项目。我有一个 datagridview,右键单击它会显示一个包含“添加到收藏夹”选项的上下文菜单。当该事件被触发时,我想使用 datagriview 中选定行中的一些文本(我已经知道如何做到这一点)将一个项目添加到此收藏夹菜单中。棘手的部分是我需要为我的newlyCreatedToolStripMenuItem_Click
事件。稍后我将确定如何保存我的收藏夹列表。
所以我们要:
右键点击datagridview
排为“约翰·史密斯”
选择“添加到收藏夹”ContextMenu
最喜欢的ToolStripMenu
添加了一个新项目,上面写着“John Smith”
单击“约翰·史密斯”ToopStripMenuItem
触发一个操作(例如在 daragridview 行中选择该行等)
有什么好的开始想法吗?
如果我理解正确,我想这正是您想要的:
private void buttonAddFav_Click(object sender, EventArgs e)
{
ToolStripItem item = new ToolStripMenuItem();
//Name that will apear on the menu
item.Text = "Jhon Smith";
//Put in the Name property whatever neccessery to retrive your data on click event
item.Name = "GridViewRowID or DataKeyID";
//On-Click event
item.Click += new EventHandler(item_Click);
//Add the submenu to the parent menu
favToolStripMenuItem.DropDownItems.Add(item);
}
void item_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)