I'm trying to read an xml file which I want to make for my mom. So basically this is what I want to do:
- A
ComboBox
which will show all the vegetable names in the XML. - After selecting a vegetable, the second
ComboBox
will show the recipe names in the XML that could use the vegetable selected in the firstComboBox
for cooking. - Last, with a OK
Button
, the selected recipe will read the file path which leads to the recipe.
XML I wrote
<Vegetables>
<vegetable name="Carrot">
<recipe name="ABCrecipe">
<FilePath>C:\\</FilePath>
</recipe>
<recipe name="DEFrecipe">
<FilePath>D:\\</FilePath>
</recipe>
</vegetable>
<vegetable name="Potato">
<recipe name="CBArecipe">
<FilePath>E:\\</FilePath>
</recipe>
<recipe name"FEDrecipe">
<FilePath>F:\\</FilePath>
</recipe>
</vegetable>
</Vegetables>
C# code
private void Form1_Load(object sender, EventArgs e)
{
XmlDocument xDoc = new XmlDocument();
xDoc.Load("Recipe_List.xml");
XmlNodeList vegetables = xDoc.GetElementsByTagName("Vegetable");
for (int i = 0; i < vegetables.Count; i++)
{
comboBox1.Items.Add(vegetables[i].Attributes["name"].InnerText);
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//I'm lost at this place.
}
The first ComboBox
is now able to display the vegetable names, but how do I make the 2nd ComboBox
to read the recipes?