20161011001 treeView 递归

protected void FillTree()
        {
            H_data H_data = new H_data();

            H_data.sql_text1 = " select [FID],[N_Name],[N_Parent_ID] FROM [PLM].[dbo].[T_Sys_File_Tree] ";
            H_data.select_tables();
            DataSet1 = H_data.DataSet8;
            DataTable dt = DataSet1.Tables[0];
            //this.dataGridView1.DataSource = dt;

            NodeLoad(0, null);
        }
        private void NodeLoad(int parentId, TreeNode upNode)
        {
            DataView dv = new DataView(DataSet1.Tables[0]);
            dv.RowFilter = string.Format("N_Parent_ID = {0}", parentId);
            foreach (DataRowView drv in dv)
            {
                if (upNode == null)
                {
                    TreeNode newNode = this.treeView1.Nodes.Add(drv[1].ToString());
                    newNode.Tag = drv[0].ToString();
                    NodeLoad(Int32.Parse(drv[0].ToString()), newNode);
                    newNode.Expand();
                }
                else
                {
                    TreeNode newNode = upNode.Nodes.Add(drv[1].ToString());
                    newNode.Tag = drv[0].ToString();
                    NodeLoad(Int32.Parse(drv[0].ToString()), newNode);
                    newNode.Expand();
                }
            }

            //展开组件中的所有节点
            //treeView1.SelectedNode.ExpandAll();
            //定位根节点
            //treeView1.SelectedNode = treeView1.Nodes[0];
            treeView1.SelectedNode = null;
        }

posted @ 2016-10-11 15:29  追逐苦痛  阅读(127)  评论(0编辑  收藏  举报