当前位置:编程学习 > C#/ASP.NET >>

请教一个关于treeview控件和contextmenu一起使用的问题。

我的意思是这样的,把treeview控件和contextmenu一起使用,要实现的功能是这样的:
当用户点击treeview的不同节点时(任何节点)弹出不同的菜单。不知道有那位高人知道怎么做,请赐教!谢谢。 --------------------编程问答-------------------- 在treeview的afterselect事件中写
if(选中节点A)
   treeview.ContextMenu = contextMenuA;
else if(选中B)
  treeview.ContextMenu = contextMenuB;
else
  treeview.ContextMenu = contextMenuC; --------------------编程问答-------------------- private void trHistory_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) 
{
 if (node != null)
            {
                nodeNumber = NodeLevel(e.Node).ToString();
ContextMenu popUpMenu = new ContextMenu();
                
                switch (nodeNumber)
                {
                    case "0":
                        popUpMenu.MenuItems.Add("受領追加", new EventHandler(Add_Click));
                        break;
                    case "1":
                        popUpMenu.MenuItems.Add("修正", new EventHandler(Change_Click));
                        popUpMenu.MenuItems.Add("症例情報", new EventHandler(Case_Click));
                        popUpMenu.MenuItems.Add("MedDRAコーディング", new EventHandler(MedDRA_Click));
                        popUpMenu.MenuItems.Add("製造販売後評価追加", new EventHandler(Add_Click));
                        break;
                    case "2":
                        popUpMenu.MenuItems.Add("修正", new EventHandler(Change_Click));
                        popUpMenu.MenuItems.Add("安全部報告追加", new EventHandler(Add_Click));
                        break;
                    case "3":
                        popUpMenu.MenuItems.Add("修正", new EventHandler(Change_Click));
                        break;
                    default:
                        break;
                }

                trHistory.ContextMenu = popUpMenu;
}
}

  private int NodeLevel(TreeNode n)
        {
            int treeNodeCount = 0;
            while (!(n.Parent == null))
            {
                n = n.Parent;
                treeNodeCount += 1;
            }
            return treeNodeCount;
        } --------------------编程问答-------------------- 好啊   谢谢
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,