首页 > 代码库 > Winform TreeList递归绑定树节点

Winform TreeList递归绑定树节点

/// <summary>/// 绑定树目录/// </summary>/// <param name="parentId">父ID</param>/// <param name="node">父节点</param>private void BindTree(int parentId, TreeListNode parentNode){    StringBuilder sb = new StringBuilder();    sb.Append("select * from tbTree order by [Index]");    DataSet ds = DbHelperSQL.QueryDataSet(sb.ToString());               DataRow[] rows = ds.Tables[0].Select("ParentID=" + parentId);    foreach (DataRow row in rows)    {        TreeListNode treeNode;        //添加根节点        if (parentNode == null)        {            treeNode = this.treeList1.AppendNode(new object[] { row["ConText"] }, null);        }        else        {            treeNode = parentNode.TreeList.AppendNode(new object[] { row["ConText"] }, parentNode);        }        BindTree(Convert.ToInt32(row["ID"]), treeNode);        treeNode.ExpandAll();    }}

 

Winform TreeList递归绑定树节点