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 su开发者_如何学运维ccessful 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;
}
}
精彩评论