利用递归绑定DevExpress.XtratreeList.TreeList数据

/// <summary>
         /// treeList绑定
        /// </summary>
         /// <param name="parent">父ID</param>
         private void TreeListBind(string parent)
         {
             treeList1.Nodes.Clear();
             if (collection.Count < 1)
                 return;
             var items = from s in collection
                         where s.Parent == parent
                         select s;
             if (items.Count() < 1)
                 return;
             TreeListNode Node = treeList1.AppendNode("id", null);
              Node.SetValue(0, "Name");
             foreach (var st in items)
             {
                 if (st.IsDeleted)
                     continue;
                 TreeListNode tn = treeList1.AppendNode(st.ID, Node);
                 tn.SetValue(treeListColumn1, st.Name);
                 tn.Tag = st;
                 GetCentralChild(tn, st.ID.ToString());
             }
             treeList1.ExpandAll();
         }
 
         private void GetCentralChild(TreeListNode tn, string parent)
         {
             var items = from s in collection
                         where s.Parent != null && s.Parent == parent
                         select s;
             if (items.Count() < 1)
                 return;
             foreach (var st in items)
             {
                 if (st.IsDeleted)
                     continue;
                 TreeListNode tns = tn.TreeList.AppendNode(st.ID, tn);
                 tns.SetValue(treeListColumn1, st.Name);
                 tns.Tag = st;
                 GetCentralChild(tns, st.ID.ToString());
             }
         }

 

posted @ 2012-12-18 15:22  therockthe  阅读(327)  评论(0)    收藏  举报