更新时间:2023-02-08 17:16:39
您可以尝试以下操作:-
You can try this:-
System.Collections.ArrayList arl = new System.Collections.ArrayList();
protected void btnSave_Click(object sender, EventArgs e)
{
foreach (TreeNode tn in TreeView1.Nodes)
{
if (tn.Checked)
{
arl.Add(tn.Text);
fetchRecursiveChild(tn);
}
fetchRecursiveChild(tn);
}
}
//需要递归获取每个节点
}
//need to fetch each node recursively
public void fetchRecursiveChild(TreeNode tn)
{
foreach (TreeNode ctn in tn.ChildNodes)
{
if (ctn.Checked)
{
arl.Add(ctn.Text);
}
fetchRecursiveChild(ctn);
}
}