简体   繁体   中英

C# winform treeview control to search xml

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.

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;
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM