1

我的应用程序上有两个组合框。第一个组合框可以获得所有需要的数据(在这种情况下是工厂编号),但是根据选择的工厂,我希望下一个组合框(在这种情况下是行号)自动填充该工厂的正确行。这是我的 XML 文件 - 或测试数据

<?xml version="1.0" encoding="utf-8"?>
<Profiles>
<Factories>
  <Factory>F1</Factory>

  <Factory>F2</Factory>

  <Factory>F3</Factory>

  <Factory>F4</Factory>

  <Factory>F5</Factory>
  <Factory>F6</Factory>
  <Factory>F7</Factory>
  <Factory>F8</Factory>
</Factories>

  <Lines>
    <F1>G1</F1>
    <F1>G2</F1>
    <F1>G3</F1>
  </Lines>
</Profiles>

这是我到目前为止所拥有的:

Private Sub populateComboBoxes()
    Dim doc As New XmlDocument()
    doc.Load("C:\TFS2010Source\ShopFloorApps\Main\Source\Components\000280LinePCBackup\000280LinePCBackup\Lines.XML")

    Dim factoryList As XmlNodeList = doc.SelectNodes("/Profiles/Factories/Factory")
    For Each Factory As XmlNode In factoryList
        factoryComboBox.Items.Add(Factory.InnerText)
    Next



End Sub

Private Sub factoryComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles factoryComboBox.SelectedIndexChanged
    Dim doc As New XmlDocument()
    doc.Load("C:\TFS2010Source\ShopFloorApps\Main\Source\Components\000280LinePCBackup\000280LinePCBackup\Lines.XML")


    Dim lineList As XmlNodeList = doc.SelectNodes("/Profiles/Lines")

    For Each line As XmlNode In lineList


        If factoryComboBox.SelectedItem.ToString = line.FirstChild.Name Then


            lineComboBox.Items.Add(line.FirstChild.InnerText)


        End If
        Next
End Sub

所以我想要的是当我选择 F1 时,另一个组合框会填充 G1、G2 和 G3 行。

谢谢

4

1 回答 1

1

您必须清除 Items 集合lineComboBox并更改SelecteNodes路径。

lineComboBox.Items.Clear()
Dim lineList As XmlNodeList = doc.SelectNodes("/Profiles/Lines/" & factoryComboBox.SelectedItem.ToString)
For Each line As XmlNode In lineList
    lineComboBox.Items.Add(line.FirstChild.InnerText)
Next
于 2012-07-10T08:33:17.203 回答