Results 1 to 6 of 6

Thread: [RESOLVED] [2005] Copy combobox items

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Resolved [RESOLVED] [2005] Copy combobox items

    How do i copy and update combobox1 items to combobox2 ?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Copy combobox items

    ComboBox1 has an Items collection. ComboBox2 has an Items collection. How would you usually copy the items from one collection to another?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Copy combobox items

    Combobox2 does not have item collection... if i knew how to copy i'd not be here at first place.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Copy combobox items

    Quote Originally Posted by LuxCoder
    Combobox2 does not have item collection
    Um, it has an Items collection, EXACTLY as I said it does.
    Quote Originally Posted by LuxCoder
    if i knew how to copy i'd not be here at first place.
    I'm not necessarily convinced of that. This is one of those things where you do already know but you just aren't putting the pieces together. If you have ever in your life added an item to a ComboBox before then you know that you add the value to the ComboBox's Items collection, just as I said:
    vb.net Code:
    1. ComboBox2.Items.Add(value)
    As I also said, just like any other collection you can loop through the items in a ComboBox's Items collection:
    vb.net Code:
    1. For Each value As Object In ComboBox1.Items
    2.  
    3. Next
    Now, put those two pieces, which I'll wager you've seen before, together and you have your solution.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2007
    Posts
    362

    Re: [2005] Copy combobox items

    I did not mean to be rude. Thanks for your help. This however has not solved my problem.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Copy combobox items

    If you take the two code snippets from my previous post and put the line from the first one inside the loop from the second one then that will do exactly what you've asked for. If it doesn't do what you want then either you haven't actually asked for the right thing or else you haven't given us all the information.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width