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

本文提供了一个在项目开发中使用dev系列treelist进行数据绑定的实例,包括如何清空节点、绑定数据以及获取子节点的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在进行项目开发过程中、曾遇到过需用到dev系列的treelist进行数据绑定、将方法贴出来希望对有需要的朋友有所帮助.
1 2 3 /// <summary> 4 /// treeList绑定 5 /// </summary> 6 /// <param name="parent">父ID</param> 7 private void TreeListBind(string parent) 8 { 9 treeList1.Nodes.Clear(); 10 if (collection.Count < 1) 11 return; 12 var items = from s in collection 13 where s.Parent == parent 14 select s; 15 if (items.Count() < 1) 16 return; 17 TreeListNode Node = treeList1.AppendNode("id", null); 18 Node.SetValue(0, "Name"); 23 foreach (var st in items) 24 { 25 if (st.IsDeleted) 26 continue; 27 TreeListNode tn = treeList1.AppendNode(st.ID, Node); 28 tn.SetValue(treeListColumn1, st.Name); 29 tn.Tag = st; 30 GetCentralChild(tn, st.ID.ToString()); 31 } 32 treeList1.ExpandAll(); 33 } 34 35 private void GetCentralChild(TreeListNode tn, string parent) 36 { 37 var items = from s in collection 38 where s.Parent != null && s.Parent == parent 39 select s; 40 if (items.Count() < 1) 41 return; 42 foreach (var st in items) 43 { 44 if (st.IsDeleted) 45 continue; 46 TreeListNode tns = tn.TreeList.AppendNode(st.ID, tn); 47 tns.SetValue(treeListColumn1, st.Name); 48 tns.Tag = st; 49 GetCentralChild(tns, st.ID.ToString()); 50 } 51 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值