take the values of an xml array

Asked

Viewed 37 times

0

Good afternoon,

I’d like to know how to add the values of an xml array to a Combox.

I am using this code but it is giving me the following error: "System.Collections.Arraylist" in the Combox

c#:

        private void Form1_Load(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("C:\\Work\\tip.xml");
            ArrayList list = new ArrayList();
            XmlNode idNodes = doc.SelectSingleNode("colors/color");
            foreach (XmlNode node1 in idNodes.ChildNodes)
                list.Add(node1.InnerText);
                comboBox1.Text = list.ToString();

        }

XML:

<colors>
    <color>
        <c1>Black</c1>
        <c2>Yellow</c2>
        <c3>White</c3>
    </color>
</colors>


1 answer

0


Assuming you are using windows Forms. Your problem is in the logic of your for. You are adding an item to your list and then trying to parse it fully for your combobox. Another thing is not with . text that fills the combobox listing. Follow the example:

private void Form1_Load(object sender, EventArgs e)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load("C:\\Work\\tip.xml");
            //ArrayList list = new ArrayList();  isso aqui não precisa
            XmlNode idNodes = doc.SelectSingleNode("colors/color");
            foreach (XmlNode node1 in idNodes.ChildNodes)
                //list.Add(node1.InnerText);
                comboBox1.Items.Add(node1.InnerText);

        }
  • thanks was just that. I’ve been chasing this hiccup for a long time.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.