Good day. The following problem arose, there is an XML file, I manage to read it and write data to the ComboBox, I would like that when I selected the required value in "Combobox" -e, not all nodes were displayed at once, but only in order. That is, if the attribute with the value "Bill Gates" is selected in the "combobox" -e, then the company and age of this particular node were displayed in the GridView. And I get everything at once ...
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { dataSet1.ReadXml(@"F:\XML1.xml"); dataGridView1.DataSource = dataSet1; dataGridView1.DataMember = "operation"; } private void button2_Click(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); doc.Load(@"F:\XML1.xml"); XmlElement element = doc.DocumentElement; foreach (XmlNode xml in element.SelectNodes("//Путь/путь")) { foreach (XmlNode child in xml.ChildNodes) { if (child.Name == "operation") { XmlNode Att = child.Attributes.GetNamedItem("info"); comboBox1.Items.Add(Att.Value); } } } }
XML example:
<?xml version="1.0" encoding="utf-8" ?> <users> <user name="Bill Gates" info="2"> <company>Microsoft</company> <age>48</age> </user> <user name="Larry Page" info="3"> <company>Google</company> <age>42</age> </user>