Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with bound combo box

Status
Not open for further replies.

Glasgow

IS-IT--Management
Jul 30, 2001
1,669
GB
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.
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
Any suggestions would be greatly appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top