I understand :) here is your solution.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Test_TreeView
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;
}
void Form1_Load(object sender, EventArgs e)
{
this.RenameNode("Node7", "Node6");
}
void RenameNode(string oldt, string newt)
{
if (CheckNodeText(this.treeView1.TopNode, newt))
return;
TreeNode n = FindNode(this.treeView1.TopNode, oldt);
if (n != null)
n.Text = newt;
}
bool CheckNodeText(TreeNode node, string text)
{
if (node.Text == text)
return true;
for (int i = 0; i < node.Nodes.Count; i++)
{
if (CheckNodeText(node.Nodes[i], text))
return true;
}
return false;
}
TreeNode FindNode(TreeNode node, string text)
{
if (node.Text == text)
return node;
for (int i = 0; i < node.Nodes.Count; i++)
{
TreeNode n = FindNode(node.Nodes[i], text);
if (n != null)
return n;
}
return null;
}
}
}