asp.net 获取TreeView中第一个选中的节点
发布时间:2016-12-29 来源:查字典编辑
摘要:复制代码代码如下:privateTreeNodeGetSelectedGroup(TreeViewtv){foreach(TreeNodei...
复制代码 代码如下:
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;
}