开发者

Removing multiple occurences of a node in an XMLNodeList or combobox

开发者 https://www.devze.com 2023-01-27 06:59 出处:网络
My objective is to search an XML document for particutar nodeS and populate a combobox with those nodes\' Id\'s.I can do this by using the folloing:

My objective is to search an XML document for particutar nodeS and populate a combobox with those nodes' Id's. I can do this by using the folloing:

        XmlNodeList nodeList = doc.SelectNodes("//开发者_StackOverflowNodeA");
        foreach (XmlNode node in nodeList)
     {
         comboBox1.Items.Add(node.Attributes["id"].Value);
     }

My problem is this. There are multiple occurances of the Xpath "//NodeA" with the same ID attribute. Therefore I end up populating the combobox with multiple occurances of these node IDs. I only want one of each in the combo box.

Can someone please assist?


if(!comboBox1.Items.Contains(node.Attributes["id"].Value))
{
 comboBox1.Items.Add(node.Attributes["id"].Value);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消