C#winform treeview控件来搜索xml

时间:2010-10-13 06:40:54

标签: c# xml winforms linq-to-xml

有人可以帮我使用C#中的代码片段来搜索(最好是linq)XML元素或使用treeview控件加载的XML中的属性吗?用户在WinForm UI中有一个搜索字符串选项卡,在成功搜索时,突出显示包含元素或属性字符串的给定节点。

1 个答案:

答案 0 :(得分:1)

试试这个:

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