Skip to content

Populating a ComboBox from an XML file

velkropie

Asked Jul 12, 2007, 6:45 AM EDT1 answer
Share
LinkedInX
Hello,

i was wondring if you could help me with this, i'm trying to load a combobox with elements from an XML file.

the problem is that the code i'm using only loads the first element.

my xml files has the following...


HTML / XML
<ITEMS> 
<NAME></NAME> 
<NAME></NAME> 
<URL></URL> 
<URL></URL> 
</ITEMS> 







so my ComboBox only shows the first name element and the first url element...any help will be great...thanks
Java
XmlDocument doc = new XmlDocument(); 
darkred]doc.Load("ComboItemName.xml"); 
XmlNodeList Nodes = doc.GetElementsByTagName("NAME"); 
foreach (XmlNode node in Nodes) 
{ 
NewNameLoad = node.InnerText.ToString(); 

} 

XmlNodeList NodesA = doc.GetElementsByTagName("URL"); 

foreach (XmlNode node in NodesA) 

{ 

NewUrlLoad = node.InnerText.ToString(); 

} 

comboChannels.Items.Add(new RSSChannel(NewNameLoad, NewUrlLoad)); 

// And select the first one 

comboChannels.SelectedIndex = 0;

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Mike Gold
    0

    It only looks like you are loading 1 element because your Items.Add for your combobox is outside the loop

    0