private void button1_Click(object sender, EventArgs e)
{
dt = DBAdo.DtFillSql("SELECT * FROM AREAS");
this.dataGridView1.DataSource = dt;
NodeLoad(0, null);
}
private void NodeLoad(int parentId, TreeNode upNode)
{
DataView dv = new DataView(dt);
dv.RowFilter = string.Format("ParentId = {0}", parentId);
foreach (DataRowView drv in dv)
{
if (upNode == null)
{
TreeNode newNode = this.treeView1.Nodes.Add(drv[1].ToString());
newNode.Tag = drv[0].ToString();
NodeLoad(Int32.Parse(drv[0].ToString()), newNode);
}
else
{
TreeNode newNode = upNode.Nodes.Add(drv[1].ToString());
newNode.Tag = drv[0].ToString();
NodeLoad(Int32.Parse(drv[0].ToString()), newNode);
}
}
}
TreeView递归添加节点
最新推荐文章于 2019-05-14 16:59:00 发布