復制代碼 代碼如下:
private TreeNode GetSelectedGroup(TreeView tv)
{
foreach (TreeNode item in tv.Nodes)
{
if (item.Checked)
{
return item;
}
else
{
return GetSelectedChildGroup(item);
}
}
return null;
}
TreeNode result = null;
private TreeNode GetSelectedChildGroup(TreeNode treeNode)
{
foreach (TreeNode item in treeNode.ChildNodes)
{
if (item.Checked)
{
return item;
}
else
{
result = GetSelectedChildGroup(item);
}
}
return result;
}