http://blog.csdn.net/xietangz/articles/243306.aspx

解决方案 »

  1.   

    数据库
    id    自动增长ID
    pid   父ID
    dept  深度
    context 接点内容        /// <summary>
            /// 连接数据库添加节点
            /// </summary>
            private void AddTree()
            {
                SqlConnection con = new SqlConnection("server=.;database=fairyland;integrated security=SSPI");
                SqlCommand cmd = con.CreateCommand();
                            string sql = "select * from addTree";
                try
                {
                    con.Open();
                    cmd.CommandText = sql;
                    SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                    adapter.Fill(ds);
                    GetTree(0, (TreeNode)null);
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                finally
                {
                    con.Close();
                }
            }        /// <summary>
            /// 循环添加节点
            /// </summary>
            /// <param name="parentId"></param>
            /// <param name="tnode"></param>
            private void GetTree(int parentId, TreeNode tnode)
            {
                DataView tv = new DataView(ds.Tables[0]);
                tv.RowFilter = "ParentID=" + parentId;
                foreach (DataRowView Row in tv)
                {
                    if (tnode == null)
                    {
                        TreeNode Node = treeView1.Nodes.Add("("+Row["ID"].ToString()+")"+Row["ConText"].ToString());
                        GetTree(Int32.Parse(Row["ID"].ToString()), Node);
                    }
                    else
                    {
                        TreeNode Node = tnode.Nodes.Add("(" + Row["ID"].ToString() + ")" + Row["ConText"].ToString());
                        GetTree(Int32.Parse(Row["ID"].ToString()), Node);
                    }
                }
            }
      

  2.   

    "ParentID= "   +   parentId,是什么意思,不明白,分别代表什么,请详解
      

  3.   

    表达式
    用于筛选dataview的数据