怎么遍历Treeview的所有节点
展开全部
public void PrintTreeViewNode(TreeNodeCollection node)
{
foreach (TreeNode n in node)
{
Response.Write(n.Text+",");
PrintTreeViewNode(n.ChildNodes);
}
}
调用 PrintTreeViewNode(TreeView1.Nodes);
//////////////////////////////////////////////////////////////////
private void button1_Click(object sender, EventArgs e)
{
label1.Text = string.Empty;
#region 递归
//1.获取TreeView的所有根节点
foreach (TreeNode tn in treeView1.Nodes)
{
DiGui(tn);
}
#endregion
}
private void DiGui(TreeNode tn)
{
//1.将当前节点显示到lable上
label1.Text += "aaa" +
" " + tn.Text
+ "\r\n";
foreach (TreeNode tnSub in tn.Nodes)
{
DiGui(tnSub);
}
}
{
foreach (TreeNode n in node)
{
Response.Write(n.Text+",");
PrintTreeViewNode(n.ChildNodes);
}
}
调用 PrintTreeViewNode(TreeView1.Nodes);
//////////////////////////////////////////////////////////////////
private void button1_Click(object sender, EventArgs e)
{
label1.Text = string.Empty;
#region 递归
//1.获取TreeView的所有根节点
foreach (TreeNode tn in treeView1.Nodes)
{
DiGui(tn);
}
#endregion
}
private void DiGui(TreeNode tn)
{
//1.将当前节点显示到lable上
label1.Text += "aaa" +
" " + tn.Text
+ "\r\n";
foreach (TreeNode tnSub in tn.Nodes)
{
DiGui(tnSub);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询