日期:2014-05-17 浏览次数:20926 次
public void LoadCloMenu() { if (this.navBarControl1.Groups.Count > 0) this.navBarControl1.Groups.Clear(); //取出父节点 DataTable table = Pro_Main_Form.GetFather_Node(); if (table != null) { if (table.Rows.Count > 0) { //循环添加节点 for (int i = 0; i < table.Rows.Count; i++) { NavBarGroupControlContainer groupCon = new NavBarGroupControlContainer(); NavBarGroup groupControl = new NavBarGroup(); //取出父节点名字 groupControl.Caption = table.Rows[i]["MenuCaption"].ToString(); //父节点属性 groupControl.Tag = table.Rows[i]; groupControl.Appearance.Font = new Font("微软雅黑", 12); //根据父节点对应的ID取出子节点 DataTable tab = Pro_Main_Form.GetChild_Node(table.Rows[i]["MenuNodeIndex"].ToString()); TreeView treeMain = new TreeView(); if (tab != null) { if (tab.Rows.Count > 0) { //循环添加子节点 for (int j = 0; j < tab.Rows.Count; j++) { TreeNode ChlidNode = new TreeNode(); ChlidNode.Text = tab.Rows[j]["MenuCaption"].ToString(); ChlidNode.Tag = tab.Rows[j]; treeMain.Nodes.Add(ChlidNode); } //展开所有节点 treeMain.ExpandAll(); treeMain.Dock = DockStyle.Fill; //添加子节点到控件下 groupCon.Controls.Add(treeMain); //设置高度 groupCon.Height = ((TreeView)groupCon.Controls[0]).Nodes.Count * 23; //展开所有节点 groupControl.Expanded = true; groupControl.ControlContainer = groupCon; } } navBarControl1.Groups.Add(groupControl); } } } }