Abdul Jeleel Kolapo
Abdul Jeleel Kolapo

Reputation: 1

Loading Combo Box from a table column name that are numbers only

I have a table whose column names are number only. Now I need to populate one combo box from that table depending on the selected value of anothe comcbo box named "cboStandard" but it is triggering error that "Child list for field 2 cannot be created". NB: The table column name are determined from the value selected in the cboStandard combo box Below is my code to populate the combo box:

Dim Series As String = (cboStandard.Text).Substring((cboStandard.Text).IndexOf(" ") + 1, 3)
If Not Series.Contains("Sys") Then
    Dim getWeights As String = "Select [" & Series & "] from StandardChicken where [" & Series & "] > 0 "
    loadcombo(getWeights, cboStandardWeights, Series)
    Dim dt As New DataTable()
    dt = ret.LoadDataTable2(getWeights)
    If Not (dt.Rows.Count = 0) Then
        cboStandardWeights.DataSource = dt
        cboStandardWeights.DisplayMember = Series
        cboStandardWeights.ValueMember = Series
        cboStandardWeights.AutoCompleteSource = AutoCompleteSource.ListItems

    ElseIf dt.Rows.Count = 0 Then
        cboStandardWeights.Text = ""
        cboStandardWeights.DataSource = dt
        cboStandardWeights.ValueMember = Series
        cboStandardWeights.DisplayMember = Series
        cboStandardWeights.AutoCompleteSource = AutoCompleteSource.ListItems
    End If
 

Upvotes: 0

Views: 81

Answers (1)

Lorenzo Martini
Lorenzo Martini

Reputation: 373

Do the following:

private sub comboBox1_EditvalueChanged(sender As Object, e As EventArgs) Handles comboBox1.EditValueChanged
  dim myValue = CInt(comboBox1.EditValue)
  if myValue = 1 then
    'populate comboBox2
  else if myValue = 2
    'populate comboBox2 with other stuff
  end if
end sub

much easier. You can do whatever you want inside, you can even hide and show the second comboBox

Upvotes: 0

Related Questions