I am generating bound textboxes and bound comboboxes dynamically and adding them to a form. The textbox code seems to work fine such that, when I step through rows in the table, the textbox contents change and show the values anticipated. The comboboxes do not behave the same way. When I step through, they consistently display the first value in the dropdown list (which has been successefully loaded from another datasource) rather than the one that corresponds to the underlying database field. The code (below) runs fine and generates all the required controls, it's just the combobox binding that does not seem to be working.
Any suggestions would be greatly appreciated.
Code:
Select Case CtlTyp
Case "txt"
Dim TxtNew As New TextBox
With TxtNew
.Width = RowFrm!FrmWidth
.Height = RowFrm!FrmHeight
.Location = NewLocation
.DataBindings.Add(New Binding("Text", DstCon, DstCon.Tables(0).TableName & "." & RowFrm!FrmFldName))
Me.Controls(RowFrm!FrmContainer).controls(TabNo).controls.add(TxtNew)
End With
Case "cmb"
Dim CmbNew As New ComboBox
With CmbNew
.Width = RowFrm!FrmWidth
.Height = RowFrm!FrmHeight
.Location = NewLocation
.DropDownStyle = ComboBoxStyle.DropDownList
Dim BndCmb As New BindingSource, DstCmb As New DataSet, SrcDat() As String
SrcDat = Split(RowFrm!FrmSource, ",")
DstCmb = PdbGetDataset("SELECT " & SrcDat(1) & ", " & SrcDat(2) & " FROM " & SrcDat(0))
BndCmb.DataSource = DstCmb : BndCmb.DataMember = DstCmb.Tables(0).TableName
.DataSource = BndCmb
.ValueMember = SrcDat(1) : .DisplayMember = SrcDat(2)
.DataBindings.Add(New Binding("Text", DstCon, DstCon.Tables(0).TableName & "." & RowFrm!FrmFldName))
Me.Controls(RowFrm!FrmContainer).controls(TabNo).controls.add(CmbNew)
End With
End Select