views:

42

answers:

1

Can someone help me with a code snippet in C# to search(linq preferably) for either XML element or attribute in a XML loaded using treeview control? The user has a search string tab in a WinForm UI and on a successful search the given node containing the element or attribute string is highlighted.

A: 

Try this:

var result = (from TreeNode node in treeView.Nodes
                      where textBox.Text.Contains(node.Text)
                      select node.Text);

        foreach (String search in result)
        {
            for (int i = 0; i < treeView.Nodes.Count - 1; i++)
            {
                if (treeView.Nodes[i].Text == search)
                    treeView.Nodes[i].BackColor = Color.Yellow;
            }
        }
Guitar-Guy