本来一行可以代替的树节点搜索
txtEditGroupCode.Text = TreeView1.SelectedNode.Text;
我用了递归。。。要多熟悉函数。。。。
protected void TreeView2_SelectedNodeChanged(object sender, EventArgs e)
{
txtEditGroupCode.Text = TreeView2.SelectedNode.Text;
foreach (TreeNode treenode in TreeView2.Nodes)
{
if (treenode.ChildNodes.Count != 0)
{
find(treenode);
}
else if (treenode.Selected == true)
{
txtEditGroupCode.Text = treenode.Value;
TreeView2.Visible = false;
}
else
continue;
}
}
protected void find(TreeNode n)
{
foreach (TreeNode childnode in n.ChildNodes)
{
if (childnode.ChildNodes.Count != 0)
find(childnode);
else if (childnode.Selected == true)
{
txtEditGroupCode.Text = childnode.Value;
TreeView2.Visible = false;
//TreeView2.SelectedNode
}
else
continue;
}
}