根据数据库结构,编写递归方法
递归,不管你有多少层都能循环出来,相关代码给你,好好去研究
private void AddTree(string ParentName, TreeNode node)
{
DataView dvTree = new DataView(dt);
dvTree.RowFilter = "[TopGovName] = '" + ParentName + "'";
foreach (DataRowView Row in dvTree)
{
TreeNode Node = node;
if (node == null)//如果根节点已经添加完成
{
Node.Text = Row["GovName"].ToString();
Node.Name = Row["sid"].ToString();
treeView1.SelectedNode.Nodes.Add(Node);
AddTree(Node.Text, Node);
}
else//进行子节点的添加
{
TreeNode nextNode = new TreeNode();
nextNode.Text = Row["GovName"].ToString();
nextNode.Name = Row["sid"].ToString();
Node.Nodes.Add(nextNode);
}
}
}