Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7764855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:01:24+00:00 2026-06-01T15:01:24+00:00

I have an application which is using a set of three combo boxes. I

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:01:25+00:00Added an answer on June 1, 2026 at 3:01 pm

    I’d change the code up somewhat to look more like this:

    'Build functions that return data, and keep them separate from code that updates your UI
    Public Function GetAccountTypesByAccountID(ByVal AccountGroupID As Integer) As DataTable
    
        Dim sql As String = "SELECT Account_Type_ID,Description FROM Tbl_Account_Type Where Account_Group_id= @AccountGroupID"
        Dim result As New DataTable()
    
        'Create a new connection each time. Really! Thanks to connection pooling, this is the way to go
        Using mcon As New SqlConnection(GetConnectionString()), _
              cmd As New SqlCommand(sql, mcon)
    
            'USE PARAMETERIZED QUERIES!!
            cmd.Parameters.Add("@AccountGroupID", SqlDbTypes.Int).Value = AccountGroupID
    
            'The Using block will make sure the connection is closed, even if an exception is thrown
            mcon.Open()
            Using rdr As SqlDataReader = cmd.ExecuteReader()
                result.Load(rdr)
            End Using
        End Using
        Return result
    End Function
    
    
    Private Sub cboAccountGroup_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As   System.EventArgs) Handles cboAccountGroup.SelectedIndexChanged
        If mblnAccountGroupFirstLoad Then Exit Sub
        mblnAccountTypeFirstLoad = False
    
        ' clearDataEntries()
    
        Dim AccountTypes As DataTable = GetAccountTypesByAccountID(Integer.Parse(cboAccountGroup.SelectedValue))
    
        cboAccountType.DisplayMember = AccountTypes.Columns(1).ColumnName
        cboAccountType.ValueMember   = AccountTypes.Columns(0).ColumnName
        cboAccountType.DataSource = AccountTypes 'Set datasoure LAST
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an ASP.net 2.0 web application which is using themes set on the
I have an application which performs 30 independent tasks simultaneously using multithreading, each task
I have created an application which stores a set five different times, at each
I have an application which i build using gcc on linux host for ARM
I have a Java application which is using a certain Java Runtime Environment. The
i have one application which is build using VB.NET now i required to add
I have a windows service application which works using remoting. It is used to
I have a application in which I am using socket programming , having this(image)
I have an application which is built from command line (ANT) using J2ME Polish.
I have an application in which I'm currently using a two column table in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.