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. C#
  4. Fill multiple comboboxes with identical information

Fill multiple comboboxes with identical information

Scheduled Pinned Locked Moved C#
comquestionworkspace
10 Posts 4 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.
  • R Offline
    R Offline
    Richard A Knox
    wrote on last edited by
    #1

    Good morning, As part of my conduit fill program, I have 8 comboboxes that require the same data filled into each one. They all have the same naming convention, but numerically different. cbo120VACType_1 cbo120VACType_2 cbo120VACType_3 cbo120VACType_4 cbo120VACType_5 cbo120VACType_6 cbo120VACType_7 cbo120VACType_8 How can I setup the naming to be dynamic in my program, so that it will fill each one, one at a time.

    Richard Disable Vet Grandfather Pain in the @ss

    OriginalGriffO R L 4 Replies Last reply
    0
    • R Richard A Knox

      Good morning, As part of my conduit fill program, I have 8 comboboxes that require the same data filled into each one. They all have the same naming convention, but numerically different. cbo120VACType_1 cbo120VACType_2 cbo120VACType_3 cbo120VACType_4 cbo120VACType_5 cbo120VACType_6 cbo120VACType_7 cbo120VACType_8 How can I setup the naming to be dynamic in my program, so that it will fill each one, one at a time.

      Richard Disable Vet Grandfather Pain in the @ss

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      The simplest way is to use an array / List of ComboBox items and preload it with the boxes to be filled. Then a simple foreach will do what you want.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      • R Richard A Knox

        Good morning, As part of my conduit fill program, I have 8 comboboxes that require the same data filled into each one. They all have the same naming convention, but numerically different. cbo120VACType_1 cbo120VACType_2 cbo120VACType_3 cbo120VACType_4 cbo120VACType_5 cbo120VACType_6 cbo120VACType_7 cbo120VACType_8 How can I setup the naming to be dynamic in my program, so that it will fill each one, one at a time.

        Richard Disable Vet Grandfather Pain in the @ss

        R Offline
        R Offline
        RobertSF
        wrote on last edited by
        #3

        Is this the same data you were previously considering how to store? A lot depends on how much data, how much the data changes, and in how many places you need the data. Suppose this one form with the eight combo boxes is the only place where you will need this data. You had mentioned building some kind of calculator or estimator, so it could conceivably consist of just one form. If that's the case, you might consider just manually entering the data in the form designer. Each combo box lets you type in the choices in the list. A step up from that would be to put the values in an array. Then use that array as the data source to a BindingSource. Then use that binding source as the data source to the first combo box. Repeat the process for the other seven combo boxes. You need one array, but you need a binding source for each combo box. This is because a binding source has only one current position, so if you use the same binding source for more than one combo box, setting one combo box will immediately set all the other combo boxes to the same selected item. Here's a similar question with code. c# - Populate a combobox with array information - Stack Overflow[^]

        L 1 Reply Last reply
        0
        • R Richard A Knox

          Good morning, As part of my conduit fill program, I have 8 comboboxes that require the same data filled into each one. They all have the same naming convention, but numerically different. cbo120VACType_1 cbo120VACType_2 cbo120VACType_3 cbo120VACType_4 cbo120VACType_5 cbo120VACType_6 cbo120VACType_7 cbo120VACType_8 How can I setup the naming to be dynamic in my program, so that it will fill each one, one at a time.

          Richard Disable Vet Grandfather Pain in the @ss

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          If it's "exactly the same", you need to create only one list in memory; you can then assign that same list to all combo boxes at the same time (.ItemSource). The CBO's will navigate the same source independently. Yes, you could use an array to assign the .ItemSource, but with 8 CBO's is not worth the effort. [c# - Bind a List<string> to a combobox - Stack Overflow](https://stackoverflow.com/questions/7025234/bind-a-liststring-to-a-combobox)

          "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

          1 Reply Last reply
          0
          • R RobertSF

            Is this the same data you were previously considering how to store? A lot depends on how much data, how much the data changes, and in how many places you need the data. Suppose this one form with the eight combo boxes is the only place where you will need this data. You had mentioned building some kind of calculator or estimator, so it could conceivably consist of just one form. If that's the case, you might consider just manually entering the data in the form designer. Each combo box lets you type in the choices in the list. A step up from that would be to put the values in an array. Then use that array as the data source to a BindingSource. Then use that binding source as the data source to the first combo box. Repeat the process for the other seven combo boxes. You need one array, but you need a binding source for each combo box. This is because a binding source has only one current position, so if you use the same binding source for more than one combo box, setting one combo box will immediately set all the other combo boxes to the same selected item. Here's a similar question with code. c# - Populate a combobox with array information - Stack Overflow[^]

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            He's using WPF; "BindingSource" is Windows Forms (navigation).

            "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

            1 Reply Last reply
            0
            • R Richard A Knox

              Good morning, As part of my conduit fill program, I have 8 comboboxes that require the same data filled into each one. They all have the same naming convention, but numerically different. cbo120VACType_1 cbo120VACType_2 cbo120VACType_3 cbo120VACType_4 cbo120VACType_5 cbo120VACType_6 cbo120VACType_7 cbo120VACType_8 How can I setup the naming to be dynamic in my program, so that it will fill each one, one at a time.

              Richard Disable Vet Grandfather Pain in the @ss

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You should say if you're using Windows Forms or WPF or UWP, etc.

              "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

              R 1 Reply Last reply
              0
              • L Lost User

                You should say if you're using Windows Forms or WPF or UWP, etc.

                "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                R Offline
                R Offline
                RobertSF
                wrote on last edited by
                #7

                Oops, thanks. I didn't pick up on that.

                L 1 Reply Last reply
                0
                • R RobertSF

                  Oops, thanks. I didn't pick up on that.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  You may be right. I thought WPF (probably because I looked at another WPF post first. I hate when I do that).

                  "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                  R 1 Reply Last reply
                  0
                  • L Lost User

                    You may be right. I thought WPF (probably because I looked at another WPF post first. I hate when I do that).

                    "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                    R Offline
                    R Offline
                    RobertSF
                    wrote on last edited by
                    #9

                    I was just surprised to hear WPF doesn't use Binding Source. I guess I'll find out what it uses when they pry WinForms out of my cold, dead hands. :)

                    L 1 Reply Last reply
                    0
                    • R RobertSF

                      I was just surprised to hear WPF doesn't use Binding Source. I guess I'll find out what it uses when they pry WinForms out of my cold, dead hands. :)

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      The WPF CB's have an ItemSource property which can share a collection and still maintain their own positioning. So it's easier. :)

                      "Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I

                      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