I have got two comboboxes on my application. The first combobox can get all the required data (in this case it is the factory numbers) however depending on which factory is selected I want the next combo box (in this case line numbers) to automatically populate with the correct lines for that factory.
Here is my XML file – or a test data
<?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>
Here is what I have so far:
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
So What I want is when I select F1 the other combobox populates with the line G1,G2 and G3.
Thanks
You have to clear the Items collection of
lineComboBoxand also change theSelecteNodespath.