日期:2014-05-17 浏览次数:20709 次
private void FindNode(TreeNode pnode, string content)
{
TreeNodeCollection nodes = pnode==null?treeView1.Nodes:pnode.Nodes;
foreach (TreeNode node in nodes)
{
if (node.Text == content)
{
treeView1.SelectedNode = node;
return;
}
else
{
FindNode(node, content);
}
}
}
使用
FindNode(null, "宣北县")
/// <summary>
/// 递归设置节点是否被选中
/// </summary>
/// <param name="nodes"></param>
private void SetSelectedNode(TreeNodeCollection nodes, string Name)
{
foreach (TreeNode node in nodes)
{
if (node.text==Name)
{
this.tvType.SelectedNode = node;
this.tvType.HideSelection = false;
return;
}
if (node.Nodes.Count > 0)
{