It's easy if you add a DataRelation
between your two tables (IIRC you can simply do this in the DataSet designer).
Then you only have to set the DisplayMember
of your second ComboBox
to ParentTable.NameOfRelation.NameToDisplay
.
Here's a small, complete example:
Dim data = New DataSet()
Dim section = data.Tables.Add("Section")
section.Columns.Add("ID", GetType(Integer))
section.Columns.Add("Name", GetType(String))
Dim sub_section = data.Tables.Add("SubSection")
sub_section.Columns.Add("ID", GetType(Integer))
sub_section.Columns.Add("Name", GetType(String))
sub_section.Columns.Add("Section", GetType(Integer))
section.Rows.Add(New Object() {1, "Foo"})
section.Rows.Add(New Object() {2, "Bar"})
sub_section.Rows.Add(New Object() {1, "Sub Foo", 1})
sub_section.Rows.Add(New Object() {2, "Another Sub Foo", 1})
sub_section.Rows.Add(New Object() {3, "Sub Bar", 2})
sub_section.Rows.Add(New Object() {4, "bar bar bar", 2})
sub_section.Rows.Add(New Object() {5, "more bar", 2})
section.ChildRelations.Add("SectionToSub", section.Columns("ID"), sub_section.Columns("Section"))
Dim f = New Form()
Dim c1 = New ComboBox() With { _
.DataSource = data, _
.DisplayMember = "Section.Name", _
.ValueMember = "Id" _
}
Dim c2 = New ComboBox() With { _
.DataSource = data, _
.DisplayMember = "Section.SectionToSub.Name", _
.ValueMember = "Id" _
}
Dim fl = New FlowLayoutPanel()
fl.Controls.Add(c1)
fl.Controls.Add(c2)
f.Controls.Add(fl)
f.ShowDialog()
Just make sure your BakerySubSections
is completly filled (no need for the parameter).