代码改变世界

一个怎样得到treeView值的小例子

2009-03-14 17:54  苏飞  阅读(691)  评论(0编辑  收藏  举报

阅读全文:http://www.cckan.net/forum.php?mod=viewthread&tid=40

private void treeViewMenu_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                Point ClickPoint = new Point(e.X, e.Y);
                TreeNode CurrentNode = treeViewMenu.GetNodeAt(ClickPoint);
                if (CurrentNode != null)//判断你点的是不是一个节点
                {
                    switch (CurrentNode.Name)//根据不同节点显示不同的右键菜单,当然你可以让它显示一样的菜单
                    {
                        case "website":
                            CurrentNode.ContextMenuStrip = ContentMenuDiy;

                            break;
                        case "company":
                            CurrentNode.ContextMenuStrip = ConentMenuMid;
                            break;
                        case "listItem":
                            CurrentNode.ContextMenuStrip = ContentMenuIthen;
                            break;
                    }
                    treeViewMenu.SelectedNode = CurrentNode;//选中这个节点
                }

            }
        }