I have a treeview with nodes.I am implementing searching through treeview nodes .Once matching node is find ,the node color should be changed .it is working fine ,but the problem is while searching for a new node the previously searched node color is also changed . Any help will be really appreciated .Thanks in advance.
protected void btn_search_Click(object sender, EventArgs e)
{
try
{
FindNodesByString();
}
catch { }
}
private void FindNodesByString()
{
foreach (TreeNode currentNode in tv_AccountView.Nodes)
{
FindNodeByString(currentNode);
}
}
private void FindNodeByString(TreeNode parentNode)
{
FindMatch(parentNode);
foreach (TreeNode currentNode in parentNode.ChildNodes)
{
//currentNode.Text = currentNode.Text;
FindMatch(currentNode);
FindNodeByString(currentNode);
}
}
private void FindMatch(TreeNode currentNode)
{
if (currentNode.Text.ToUpper().Contains(txt_searchbyname.Text.ToUpper()))
{
currentNode.Expand();
currentNode.Text = "<div style='background-
color:#ffffcc;color:#ff9900;'>" + currentNode.Text + "
</div>";
}
else
{
currentNode.Text = currentNode.Text;
// currentNode.Collapse();
// currentNode.ShowCheckBox = false;
}
}