DevExpress组件之——TreeList组件
由于是第一次接触到第三方控件DevExpress中的TreeList,对其进行了进一步的研究,采用递归算法实现。做下自己熟悉第三方控件的整个过程,为和我一样处理于起步阶段的同仁们提供个参考,以下为最终效果
1、以下是代码实现
代码
1 //加载行政区数据
2 public void LoadDistrictData()
3 {
4 string distsql = "select * from district";
5 DataTable dataTable = _dbhelp.GetDataTable(distsql);
6 this.tvDist.Nodes.Clear();
7 TreeListNode treenode = tvDist.AppendNode(new object[] { "广西壮族自治区" }, null);
8 treenode.Tag = 1000;
9 treenode.Expanded = false;
10 CreateChildNodes(treenode, dataTable);
11 tvDist.Nodes[0].Expanded = true;
12 }
13
14 private void CreateChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, DataTable dataTable)
15 {
16 DataRow[] rowList = dataTable.Select("SUPERID = '" + node.Tag + "'");
17 foreach (DataRow row in rowList)
18 {
19 TreeListNode tempNode = this.tvDist.AppendNode(new object[] { row["NAME"] }, node);
20 tempNode.Tag = row["ID"];
21 CreateChildNodes(tempNode, dataTable);
22 }
23 }
2 public void LoadDistrictData()
3 {
4 string distsql = "select * from district";
5 DataTable dataTable = _dbhelp.GetDataTable(distsql);
6 this.tvDist.Nodes.Clear();
7 TreeListNode treenode = tvDist.AppendNode(new object[] { "广西壮族自治区" }, null);
8 treenode.Tag = 1000;
9 treenode.Expanded = false;
10 CreateChildNodes(treenode, dataTable);
11 tvDist.Nodes[0].Expanded = true;
12 }
13
14 private void CreateChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, DataTable dataTable)
15 {
16 DataRow[] rowList = dataTable.Select("SUPERID = '" + node.Tag + "'");
17 foreach (DataRow row in rowList)
18 {
19 TreeListNode tempNode = this.tvDist.AppendNode(new object[] { row["NAME"] }, node);
20 tempNode.Tag = row["ID"];
21 CreateChildNodes(tempNode, dataTable);
22 }
23 }