views:

118

answers:

1

i want to check the combobox.selecteditem.tostring() on combobox select in a given xml with several nodes, where each one has an attribute called "name"

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    try
    {
        textBox1.AppendText(nameAttributeCheck(comboBox1.SelectedItem.ToString()));
    }
    catch { 
    }
}

private string nameAttributeCheck(string a)
{
    XmlDocument doc = new XmlDocument();
    doc.Load("armor.xml");

    XmlElement root = doc.DocumentElement;
    XmlNodeList items = root.SelectNodes("/items");

    String result = null;

    try
    {
        foreach (XmlNode item in items)
        {
                if (string.Equals(a, item.Attributes["name"].InnerText.ToString()))
                {
                    result += item.Attributes["picture"].InnerText.ToString();
                }
        }

    }
    catch
    {
    }
    return result;

}

each time i try it, nothing happens

A: 

ok i got it

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { textBox1.AppendText(nameAttributeCheck(comboBox1.SelectedItem.ToString())); } catch { } }

private string nameAttributeCheck(string a)
{
    XmlDocument doc = new XmlDocument();
    doc.Load("armor.xml");

    XmlElement root = doc.DocumentElement;
    XmlNodeList items = root.SelectNodes("/items/item");

    String result = null;

    try
    {
            for (int i = 0; i < items.Count; i++)
            {

                if (string.Equals(a, items[i].Attributes["name"].InnerText.ToString()))
                {
                    result += items[i].Attributes["name"].InnerText.ToString();
                }
            }               
    }
    catch
    {
    }
    return result;
fuch