DevExpress组件之——TreeList组件

 由于是第一次接触到第三方控件DevExpress中的TreeList,对其进行了进一步的研究,采用递归算法实现。做下自己熟悉第三方控件的整个过程,为和我一样处理于起步阶段的同仁们提供个参考,以下为最终效果

1、以下是代码实现

代码

Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> 1 //加载行政区数据
public void LoadDistrictData()
{
    string distsql = "select * from district";
    DataTable dataTable = _dbhelp.GetDataTable(distsql);
    this.tvDist.Nodes.Clear();
    TreeListNode treenode = tvDist.AppendNode(new object[] { "广西壮族自治区" }, null);
    treenode.Tag = 1000;
    treenode.Expanded = false;
    CreateChildNodes(treenode, dataTable);
    tvDist.Nodes[0].Expanded = true;
}

private void CreateChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, DataTable dataTable)
{
    DataRow[] rowList = dataTable.Select("SUPERID = '" + node.Tag + "'");
    foreach (DataRow row in rowList)
    {
        TreeListNode tempNode = this.tvDist.AppendNode(new object[] { row["NAME"] }, node);
        tempNode.Tag = row["ID"];
        CreateChildNodes(tempNode, dataTable);
    }
}

 

posted @ 2013-10-11 15:47  Jara  阅读(621)  评论(0编辑  收藏  举报