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 fill the list of one combo box to another combo box?

How to fill the list of one combo box to another combo box?

Scheduled Pinned Locked Moved Visual Basic
databasehelptutorialquestion
5 Posts 3 Posters 1 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.
  • R Offline
    R Offline
    Ravi S V
    wrote on last edited by
    #1

    I have a form which is having two combo boxes. This two combo boxes contains the same list. This list is retrieved from the database. First, I am filling the first combo box and then i am filling the second combo box. This is taking more time. Is there any method which I can fill the second combo box with the first one? Please Help me... Thanx, Ravi.

    D 1 Reply Last reply
    0
    • R Ravi S V

      I have a form which is having two combo boxes. This two combo boxes contains the same list. This list is retrieved from the database. First, I am filling the first combo box and then i am filling the second combo box. This is taking more time. Is there any method which I can fill the second combo box with the first one? Please Help me... Thanx, Ravi.

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The easiest way to do it would be to copy the items, one at a time, from one combobox to the other.

      Dim index As Integer
      ComboBox2.Items.Clear()
      For Index = 0 To ComboBox1.Items.Count() - 1
          ComboBox2.Items.Add( ComboBox1.Items(Index) )
      Next
      

      Or you could bind the Items collection of one Combobox to the other.

      ComboBox2.DataBindings.Add(New \_
           Binding("Items", ComboBox1.Items, "")
      

      RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      B R 2 Replies Last reply
      0
      • D Dave Kreskowiak

        The easiest way to do it would be to copy the items, one at a time, from one combobox to the other.

        Dim index As Integer
        ComboBox2.Items.Clear()
        For Index = 0 To ComboBox1.Items.Count() - 1
            ComboBox2.Items.Add( ComboBox1.Items(Index) )
        Next
        

        Or you could bind the Items collection of one Combobox to the other.

        ComboBox2.DataBindings.Add(New \_
             Binding("Items", ComboBox1.Items, "")
        

        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        B Offline
        B Offline
        beowulfagate
        wrote on last edited by
        #3

        Try using the CopyTo method of the first combobox to copy its contents to an array then use the AddRange method of the second combobox to copy the array.

        1 Reply Last reply
        0
        • D Dave Kreskowiak

          The easiest way to do it would be to copy the items, one at a time, from one combobox to the other.

          Dim index As Integer
          ComboBox2.Items.Clear()
          For Index = 0 To ComboBox1.Items.Count() - 1
              ComboBox2.Items.Add( ComboBox1.Items(Index) )
          Next
          

          Or you could bind the Items collection of one Combobox to the other.

          ComboBox2.DataBindings.Add(New \_
               Binding("Items", ComboBox1.Items, "")
          

          RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          R Offline
          R Offline
          Ravi S V
          wrote on last edited by
          #4

          There is no other method in VB6

          D 1 Reply Last reply
          0
          • R Ravi S V

            There is no other method in VB6

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            You didn't say you were using VB6 before. Is there some reason you can't fill both ComboBoxes at the same time? That way, you're only enumerating the data once. Otherwise, you have to enumerate the data again, either from the datasource or from the first ComboBox, to fill the second ComboBox. You could still try databinding, but it's a bit more complex than the .NET version. Try this[^] for an example in VB6. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            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