WINform里面怎么做树状列表 的菜单
WINform里面怎么做树状列表 的菜单 可伸缩的那种
谁有代码或者例子发一个啊
277011927@qq.com
感激不尽!
------解决方案--------------------
tvType:treeview控件
contextMenuStrip1:右键菜单s
View Code
#region 创建树形菜单 /// <summary> /// 描述:创建树形菜单 /// </summary> public void AddTree(int ParentID, TreeNode pNode) { DataTable dt = typeManager.GetAllList().Tables[0]; DataView dvTree = new DataView(dt); //过滤ParentID,得到当前的所有子节点 dvTree.RowFilter = "ComType_ParentID = " + ParentID; foreach (DataRowView Row in dvTree) { TreeNode Node = new TreeNode(); if (pNode == null) { //添加根节点 Node.Text = Row["CommodityTypeName"].ToString(); Node.Name = Row["CommodityTypeName"].ToString(); Node.Tag = Row["CommodityTypeID"].ToString(); this.tvType.Nodes.Add(Node); //Node.Expanded = true; AddTree(Int32.Parse(Row["CommodityTypeID"].ToString()), Node); //再次递归 } else { //添加当前节点的子节点 Node.Text = Row["CommodityTypeName"].ToString(); Node.Name = Row["CommodityTypeName"].ToString(); Node.Tag = Row["CommodityTypeID"].ToString(); pNode.Nodes.Add(Node); //Node.Expanded = true; AddTree(Int32.Parse(Row["CommodityTypeID"].ToString()), Node); //再次递归 } } } #endregion #region 主窗体加载 /// <summary> /// 主窗体加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CommodityForm_Load(object sender, EventArgs e) { this.tvType.Nodes.Clear(); AddTree(0, (TreeNode)null); } #endregion #region treeview操作 /// <summary> /// 新增同级 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 新增同级ToolStripMenuItem_Click(object sender, EventArgs e) { AddPeerType aptForm = new AddPeerType(); DialogResult d = aptForm.ShowDialog(); if (d == DialogResult.OK) { Emp.tagComType = "1"; Emp.parentTagComType = "0"; this.tvType.Nodes.Clear(); AddTree(0, (TreeNode)null); } } /// <summary> /// 新增下一级 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 新增下一级ToolStripMenuItem_Click(object sender, EventArgs e) { AddLowerType altForm = new AddLowerType(); DialogResult d = altForm.ShowDialog(); if (d == DialogResult.OK) { Emp.tagComType = "1"; Emp.parentTagComType = "0"; this.tvType.Nodes.Clear(); AddTree(0, (TreeNode)null); } } /// <summary> /// 单击树上一个节点事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tvType_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (e.Node.Text != "所有商品") { 删除类别ToolStripMenuItem.Enabled = true; 新增同级ToolStripMenuItem.Enabled = true; 修改类别ToolStripMenuItem.Enabled = true;