在进行项目开发过程中、曾遇到过需用到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 }
Treelist数据绑定方法
本文介绍了一种使用dev系列的treelist组件进行数据绑定的方法,通过递归方式实现了树形结构的数据展示。适用于需要构建复杂层级结构的应用场景。
1387

被折叠的 条评论
为什么被折叠?



