利用递归绑定DevExpress.XtratreeList.TreeList数据
在进行项目开发过程中、曾遇到过需用到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 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构