1

ここでいくつかの例を見ましたが、正しい手順に従っているように見えますが、まだ機能していないため、明らかに何か間違っています。XMLファイルから入力しようとしている2つのコンボボックスがあります。アイデアは、最初の選択が行われると、セカンダリコンボボックスの一連の選択肢が生成され、最初の選択を切り替えると、セカンダリコンボボックスが次のように更新されるということです良い

これは私のXMLです

<?xml version="1.0" encoding="utf-8"?>
<ComboBox>
    <Customer name="John"/>
        <Data>
            <System>Linux</System>
        </Data>
    <Customer name="Fernando"/>
        <Data>
            <System>Microsoft</System>
            <System>Mac</System>
        </Data>
</ComboBox>

これは私のC#コードです

//This part works the customer_comboBox is generated correctly with John and Fernando

 XmlDocument doc = new XmlDocument();
 doc.Load(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +@"\comboBox.xml");
 XmlNodeList customerList = doc.SelectNodes("ComboBox/Customer");

 foreach (XmlNode node in customerList)
 {
     customer_comboBox.Items.Add(node.Attributes["name"].InnerText);
 }

//putting the selected item from the first comboBox in a string
string selected_customer = customer_comboBox.SelectedItem.ToString();

//This is the part that does not work
//I want to read XML node that matches selected_customer and populate systems available

foreach (XmlNode node in customerList)
{
      if (node.Attributes["name"].InnerText == selected_customer) 
      {
          foreach (XmlNode child in node.SelectNodes("ComboBox/Customer/Data"))
          {
             system_comboBox.Items.Clear();
             system_comboBox.Items.Add(node["System"].InnerText); 
          }
      } 
}

私はこれを理解しようと2日間続けました。XML が間違っているのか、それとも子ノードを呼び出す方法が間違っているのかわかりません。

4

1 に答える 1