Public Class Form1
Private myData As DataTable
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
GetData()
' This code assumes you have 2 combo boxes on the form
' Combobox1 and Combobox2 for 'Chocolate' and 'Topping' accordingly
' Querying the datatable for distinct values in the
' first column (first choice)
Dim choice1 = _
From row As DataRow In myData.Rows.Cast(Of DataRow)() _
Select row.Item("Chocolate") Distinct.ToArray
ComboBox1.DataSource = choice1
ComboBox1.DisplayMember = "Chocolate"
End Sub
''' <summary>
''' This handler is fired when a user makes the first choice
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub ComboBox1_SelectedIndexChanged( _
ByVal sender As Object, ByVal e As System.EventArgs) _
Handles ComboBox1.SelectedIndexChanged
Dim choice1 As String = ComboBox1.SelectedItem.ToString
' Querying for the second choices from the data table
Dim choice2 = _
From row As DataRow In myData.Rows.Cast(Of DataRow)() _
Where row.Item("Chocolate").ToString = choice1 _
Select row.Item("Topping") Distinct.ToArray
ComboBox2.DataSource = choice2
ComboBox2.DisplayMember = "Topping"
End Sub
''' <summary>
''' This sub is for example only. Normally you'd need to get
''' your choices table from a database or some other data source
''' </summary>
''' <remarks></remarks>
Private Sub GetData()
myData = New DataTable("Choices")
myData.Columns.Add(New DataColumn("Chocolate", GetType(System.String)))
myData.Columns.Add(New DataColumn("Topping", GetType(System.String)))
myData.Rows.Add(New String() {"milk", "nuts"})
myData.Rows.Add(New String() {"milk", "raisins"})
myData.Rows.Add(New String() {"strawberry", "sweetened"})
myData.Rows.Add(New String() {"strawberry", "unsweetened"})
End Sub
End Class