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);
}
精彩评论