Share (or import/export) a ComboBox between 2 forms?
-
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
-
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
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.”
-
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.”
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.
-
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.
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 bothComboBoxes
. Either by having the list in a library assembly, or by passing it as a parameter to the constructor of theForm
(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.”
-
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 bothComboBoxes
. Either by having the list in a library assembly, or by passing it as a parameter to the constructor of theForm
(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.”
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
-
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
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... -
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...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
-
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
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:
-
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:
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
-
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
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: