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. Share (or import/export) a ComboBox between 2 forms?

Share (or import/export) a ComboBox between 2 forms?

Scheduled Pinned Locked Moved Visual Basic
helpperformancetutorialquestion
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.
  • H Offline
    H Offline
    Hurricane3000
    wrote on last edited by
    #1

    Hi all, I have a little problem and I hope to find some help: I'm developing a program (C.F.2-V.B.)that have multiple forms. I need that when I switch from Form1 to Form2, I can continuing to use some of controls builded in Form1. For example, if in Form1 I have a ComboBox1 populated with its appropiate items, when I switch on Form2, I need to have the same ComboBox1 (without the need to build a new ComboBox and re-populate it with same values). Is it possible? This to avoid to do 2 time the same work, and to save precious memory of device. Thanks Ignazio

    H 1 Reply Last reply
    0
    • H Hurricane3000

      Hi all, I have a little problem and I hope to find some help: I'm developing a program (C.F.2-V.B.)that have multiple forms. I need that when I switch from Form1 to Form2, I can continuing to use some of controls builded in Form1. For example, if in Form1 I have a ComboBox1 populated with its appropiate items, when I switch on Form2, I need to have the same ComboBox1 (without the need to build a new ComboBox and re-populate it with same values). Is it possible? This to avoid to do 2 time the same work, and to save precious memory of device. Thanks Ignazio

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      Hurricane3000 wrote:

      I need to have the same ComboBox1 (without the need to build a new ComboBox and re-populate it with same values)

      Why? How much work is involved?

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      H 1 Reply Last reply
      0
      • H Henry Minute

        Hurricane3000 wrote:

        I need to have the same ComboBox1 (without the need to build a new ComboBox and re-populate it with same values)

        Why? How much work is involved?

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        H Offline
        H Offline
        Hurricane3000
        wrote on last edited by
        #3

        Hi, I want avoid to have a duplicate of the same ComboBox in memory for 3 reasons: 1 - because application is for devices (Compact Framework)where memory must be used with parsimony. It can contain also 20,000 items 2 - To make more fast application avoiding to populate 2 times 2 different Combobox with the same data. 3 - Because to have 2 ComboBox with same items in the same program not sounds to be an "efficent" solution.

        H 1 Reply Last reply
        0
        • H Hurricane3000

          Hi, I want avoid to have a duplicate of the same ComboBox in memory for 3 reasons: 1 - because application is for devices (Compact Framework)where memory must be used with parsimony. It can contain also 20,000 items 2 - To make more fast application avoiding to populate 2 times 2 different Combobox with the same data. 3 - Because to have 2 ComboBox with same items in the same program not sounds to be an "efficent" solution.

          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          In that case you might have done better to post your question in the Mobile Development Forum, although it does not seem to be as active as this one. I have zero exposure to the Compact Framework and therefore do not even know if this would work but you might have one list and use that as the DataSource for both ComboBoxes. Either by having the list in a library assembly, or by passing it as a parameter to the constructor of the Form(s). Sorry not to be more help. :)

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          H 1 Reply Last reply
          0
          • H Henry Minute

            In that case you might have done better to post your question in the Mobile Development Forum, although it does not seem to be as active as this one. I have zero exposure to the Compact Framework and therefore do not even know if this would work but you might have one list and use that as the DataSource for both ComboBoxes. Either by having the list in a library assembly, or by passing it as a parameter to the constructor of the Form(s). Sorry not to be more help. :)

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            H Offline
            H Offline
            Hurricane3000
            wrote on last edited by
            #5

            Thanks Henry! Ufortunately in my case the DataSource property is not appliable (and also I don't think that I can have some benefit.) If not possible differentely, I necessarily will must have 2 ComboBoxes. Ignazio

            D 1 Reply Last reply
            0
            • H Hurricane3000

              Thanks Henry! Ufortunately in my case the DataSource property is not appliable (and also I don't think that I can have some benefit.) If not possible differentely, I necessarily will must have 2 ComboBoxes. Ignazio

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

              I just got done telling someone else this same thing. You cannot have the same instance of a control in two different containers (forms) at the same time. You can add the combo to the controls collection of the second form by first removing it from the controls collection of the first form. You'll have to move it back before your second form is destroyed or dismissed. 20,000 items in a combo?? I'd seriously rethink the design...

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008
              But no longer in 2009...

              H 1 Reply Last reply
              0
              • D Dave Kreskowiak

                I just got done telling someone else this same thing. You cannot have the same instance of a control in two different containers (forms) at the same time. You can add the combo to the controls collection of the second form by first removing it from the controls collection of the first form. You'll have to move it back before your second form is destroyed or dismissed. 20,000 items in a combo?? I'd seriously rethink the design...

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                     2006, 2007, 2008
                But no longer in 2009...

                H Offline
                H Offline
                Hurricane3000
                wrote on last edited by
                #7

                Thanks Dave, 20,000 items is the maximum, but normally I need to fill the Combo with less than 10,000 items getting data from a text-file. Applying your suggestion, items are preserved , or will be necessary to re-populate the Combo? Ignazio

                L 1 Reply Last reply
                0
                • H Hurricane3000

                  Thanks Dave, 20,000 items is the maximum, but normally I need to fill the Combo with less than 10,000 items getting data from a text-file. Applying your suggestion, items are preserved , or will be necessary to re-populate the Combo? Ignazio

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  Hi, 1. As Dave said, a Control has a single Parent, i.e. one Form holding it. You can't make it work reliably on two forms at the same time. 2. You might consider replacing your two forms by a single form holding: 1. the common controls (including your ComboBox) once; 2. a TabControl so you can choose which TabPage you want to see (so these pages would contain what was not common on your forms). 3. anything above 100 items in a list for a user to choose from is a GUI horror. You should avoid this both for the user comfort and for performance; there are many ways to avoid it, most of them have a two-level approach: select something (maybe the first letter of a name, a range of values, a page number, whatever), then in a second control show what satisfies the first selection. One elegant example is a collapsed TreeView: show all the top-level nodes, but only load the details when one of the nodes gets expanded. :)

                  Luc Pattyn

                  :badger: :jig: :badger:

                  Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.

                  :jig: :badger: :jig:

                  H 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Hi, 1. As Dave said, a Control has a single Parent, i.e. one Form holding it. You can't make it work reliably on two forms at the same time. 2. You might consider replacing your two forms by a single form holding: 1. the common controls (including your ComboBox) once; 2. a TabControl so you can choose which TabPage you want to see (so these pages would contain what was not common on your forms). 3. anything above 100 items in a list for a user to choose from is a GUI horror. You should avoid this both for the user comfort and for performance; there are many ways to avoid it, most of them have a two-level approach: select something (maybe the first letter of a name, a range of values, a page number, whatever), then in a second control show what satisfies the first selection. One elegant example is a collapsed TreeView: show all the top-level nodes, but only load the details when one of the nodes gets expanded. :)

                    Luc Pattyn

                    :badger: :jig: :badger:

                    Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.

                    :jig: :badger: :jig:

                    H Offline
                    H Offline
                    Hurricane3000
                    wrote on last edited by
                    #9

                    Hi, Your suggestion to implement a Tab Control is to consider if in this way there is not the need to re-populate the combo 2 times. I choosen a Combo to contain 10,000 items as compromise between several exigences including the limitaded space available in a mobile device. I tryed to use a DataGrid, but I confess I encoutered some difficulties. Thanks Ignazio

                    L 1 Reply Last reply
                    0
                    • H Hurricane3000

                      Hi, Your suggestion to implement a Tab Control is to consider if in this way there is not the need to re-populate the combo 2 times. I choosen a Combo to contain 10,000 items as compromise between several exigences including the limitaded space available in a mobile device. I tryed to use a DataGrid, but I confess I encoutered some difficulties. Thanks Ignazio

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #10

                      with the ComboBox outside the TabControl it would always be visible and have no need to repopulate, unless you want to. :)

                      Luc Pattyn

                      :badger: :jig: :badger:

                      Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.

                      :jig: :badger: :jig:

                      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