2层for循环生成 TreeView

C# TreeView 利用2层for循环生成,代码如下:
//生成树 treeView1.Nodes.Clear(); //封装了数据库查询方法 MyDS_Grid = MyDataClass.getDataSet("SELECT * FROM table;", "tablename"); for (int i = 0; i < MyDS_Grid.Tables[0].Rows.Count; i++) { //将一级菜单项的名称添加到TreeView组件的根节点中,并设置当前节点的子节点newNode1 TreeNode newNode1 = treeView1.Nodes.Add(MyDS_Grid.Tables[0].Rows[i][1].ToString()); DataSet Area_Grid = MyDataClass.getDataSet("SELECT * FROM table where ID = '"+ MyDS_Grid.Tables[0].Rows[i][0]+"'", "tablename"); for (int j = 0; j < Area_Grid.Tables[0].Rows.Count; j++) { newNode1.Nodes.Add(Area_Grid.Tables[0].Rows[j][2].ToString()); } }
效果图如下:
TreeView

posted @ 2024-02-28 21:44  瘦腿先生Stephen  阅读(24)  评论(1编辑  收藏  举报