Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to create a chained combobox

How to create a chained combobox

Scheduled Pinned Locked Moved Visual Basic
databasehelptutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    braathaa
    wrote on last edited by
    #1

    i want to create 2 combobox st combobox = country nd combobox = district/region st combobox is the country combobox. when i choose one country , the nd combobox will change / auto populate all the region based on the selected country . all the data is populate from access database . im new to VB . appreciate ur help :thumbsup:

    B P 2 Replies Last reply
    0
    • B braathaa

      i want to create 2 combobox st combobox = country nd combobox = district/region st combobox is the country combobox. when i choose one country , the nd combobox will change / auto populate all the region based on the selected country . all the data is populate from access database . im new to VB . appreciate ur help :thumbsup:

      B Offline
      B Offline
      Bernhard Hiller
      wrote on last edited by
      #2

      A combobox has an event for the change of a selection, e.g. SelectionChanged or SelectedIndexChanged. In the corresponding event handler, get the SelectedItem of the combobox. Caution: it might be "Nothing". If it is not Nothing, query your database to get the regions. Make the regions combobox empty (e.g. comboregions.Items.Clear()), and fill the new data into it. You could then set the SelectedIndex to 0 to preselect the first item in the combobox.

      1 Reply Last reply
      0
      • B braathaa

        i want to create 2 combobox st combobox = country nd combobox = district/region st combobox is the country combobox. when i choose one country , the nd combobox will change / auto populate all the region based on the selected country . all the data is populate from access database . im new to VB . appreciate ur help :thumbsup:

        P Offline
        P Offline
        ProEnggSoft
        wrote on last edited by
        #3

        The solution given by Bernhard Hiller works fine. Another option is in the DataSet designer or programmatically, create a relation between Country and Region DataTables like Relation Name: CountryRegion Parent Table: Country, primary key: CountryID Child Table: Region, Foreign key: CountryID

        'Now create a BindingSource for Country ComboBox
        Dim CountryBindingSource As New BindingSource(DataSet1, "Country")
        'Then create a binding source with CountryBindingSource as the parent using the relation
        Dim RegionBindingSource As New BindingSource(CountryBindingSource, "CountryRegion")
        'Now set the DataSource, DisplayMember and ValueMember properties of both the ComboBoxes
        comboBox1.DataSource = CountryBindingSource
        comboBox1.DisplayMember = "Country"
        comboBox1.ValueMember = "CountryID"
        comboBox2.DataSource = RegionBindingSource
        comboBox2.DisplayMember = "Region"
        comboBox2.ValueMember = "RegionID"

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups