I have a some TreeViews that only contains parent nodes (like a listview). I have a textbox where user can enter a text, then I want to highlight the node in the treeview which has same text as entered by user. At the moment I use this code:
strring text = textBox.Text.Trim(); //the text entered by user
foreach(TreeNode node in treeView.Nodes)
{
if(node.Text == text) node.BackColor == Color.Green;
}
I hate writing foreach for each treeview. Is there a simple way to say for example:
if(treeView.Nodes.Contains(text)) //do stuff
the Nodes.Contains() only accept a TreeNode object. I was wondering if a better code exist out there!?
Yes, you can do it with LINQ like that:
You will get null, if no item was found.