I have an application which is using a set of three combo boxes.
I have managed to populate each drop down depending on the selected value of the previous one
The only problem is that, since the data is coming the database two selected values from the first combo box may have two different number of items in the database. so the second combobox should be populated with such data each time the selectedIndex_changed nethod of the first combobox is invoked
if for example, the first combo box’s first item has 10 corresponding items in the second combo box and a first combo box’s second item has three corresponding items in the second combo box, selecting the second item after selecting the first item will lead to second combobox showing the three items and seven empty entries trailing after the three.
What I want is to have the second combobox loaded with three items exactly when the second item in the first combo box has three items in the database
here is an example
Private Sub cboAccountGroup_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboAccountGroup.SelectedIndexChanged
If mblnAccountGroupFirstLoad = True Then
Exit Sub
End If
Dim index As String
index = cboAccountGroup.SelectedValue
'Call clearDataEntries()
Dim psql As String
psql = "Select Account_Type_ID,Description from Tbl_Account_Type Where Account_Group_id=" & index
Call setDropDowns(cboAccountType, psql)
mblnAccountTypeFirstLoad = False
End Sub
The setDropDowns is defined as follows
Public Sub setDropDowns(ByRef combo As ComboBox, ByVal sql As String)
Try
Dim adaptor As New SqlDataAdapter(sql, mcon)
Dim dataset As New DataTable()
mcon.Open()
adaptor.Fill(DataSet)
mcon.Close()
combo.DataSource = DataSet
combo.DisplayMember = DataSet.Columns(1).ColumnName
combo.ValueMember = DataSet.Columns(0).ColumnName
Catch ex As Exception
Finally
'mcon.Close()
End Try
End Sub
Please assist.
I’d change the code up somewhat to look more like this: