首页 > 代码库 > DevExpress TreeList利用递归绑定数据

DevExpress TreeList利用递归绑定数据

 private void TreeListBind(DataTable dt, int p)        {            treeList1.Nodes.Clear();            if (dt.Rows.Count < 1)                return;            DataView dv = new DataView(dt);            dv.RowFilter = "ParentFieldName=" + p;            if (dv.Count < 1)                return;            TreeListNode Node = treeList1.AppendNode("id", null);            Node.SetValue(treeListColumn1,"第一个节点名");            foreach (DataRowView dv1 in dv)            {                TreeListNode tn = treeList1.AppendNode(dv1["KeyFieldName"], Node);                tn.SetValue(treeListColumn1, dv1["NodeName"]);                tn.Tag = dv1;                GetCentralChild(dt,tn, Convert.ToInt16(dv1["KeyFieldName"]));            }        }        private void GetCentralChild(DataTable dt, TreeListNode tn, int p)        {            DataView dv = new DataView(dt);            dv.RowFilter = "ParentFieldName=" + p;            if (dv.Count < 1)                return;            foreach (DataRowView dv1 in dv)            {                TreeListNode tns = tn.TreeList.AppendNode(dv1["KeyFieldName"], tn);                //TreeListNode tn = treeList1.AppendNode(dv1["KeyFieldName"], Node);                tns.SetValue(treeListColumn1, dv1["NodeName"]);                tns.Tag = dv1;                GetCentralChild(dt, tns, Convert.ToInt16(dv1["KeyFieldName"]));            }        }