asp.Net TreeViewで最初に選択したノードを取得

720 ワード

 
  
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;
}