473,320 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Copy items to another combobox?

Hi,
I am trying to duplicate the contents of a combobox to another.
I tried:

cmbBoxA.Items.AddRange(cmbBoxB.Items);

but it says it can't convert a combobox objectcollection[] to object[].

I tried putting (Object[]) in front of the addrange parameter but get a
similar error.
Any idea? I did something similar with a ListView and it worked fine...

James.

Jan 3 '07 #1
3 18977
This works, although I don't know if it's optimal.

comboBox1.Items.Add("an item");
object[] a= new object[comboBox1.Items.Count];
comboBox1.Items.CopyTo(a,0);
comboBox2.Items.AddRange(a);
james wrote:
Hi,
I am trying to duplicate the contents of a combobox to another.
I tried:

cmbBoxA.Items.AddRange(cmbBoxB.Items);

but it says it can't convert a combobox objectcollection[] to object[].

I tried putting (Object[]) in front of the addrange parameter but get a
similar error.
Any idea? I did something similar with a ListView and it worked fine...

James.
Jan 3 '07 #2

"DeveloperX" <nn*****@operamail.comwrote in message
news:11**********************@h40g2000cwb.googlegr oups.com...
This works, although I don't know if it's optimal.

comboBox1.Items.Add("an item");
object[] a= new object[comboBox1.Items.Count];
comboBox1.Items.CopyTo(a,0);
comboBox2.Items.AddRange(a);
I'll give it a try - there won't be too many items, so optimal isn't too
much of a worry.

I also lied - copying listview items like that doesn't work! It compiles,
but at runtime, it says I can't have that item in more than one location
unless I clone it?

Jan 3 '07 #3
Yeah listviews use ListViewItem objects as opposed to just a bunch of
objects. ListViewItem has a clone method on it for that :)

james wrote:
"DeveloperX" <nn*****@operamail.comwrote in message
news:11**********************@h40g2000cwb.googlegr oups.com...
This works, although I don't know if it's optimal.

comboBox1.Items.Add("an item");
object[] a= new object[comboBox1.Items.Count];
comboBox1.Items.CopyTo(a,0);
comboBox2.Items.AddRange(a);
I'll give it a try - there won't be too many items, so optimal isn't too
much of a worry.

I also lied - copying listview items like that doesn't work! It compiles,
but at runtime, it says I can't have that item in more than one location
unless I clone it?
Jan 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Newbee | last post by:
Hola I wanted to kno how to clear the current text that is displayed in my combobox I am filling it with a query which is run against my database I have tried this but it not work ...
1
by: Bill Manring | last post by:
I am adding items to a combo box, but they are not visible when the drop down list is displayed. Ther items arethere because I canclick on the drop down list and the items show up in the text box....
4
by: Georges Heinesch | last post by:
Hi. I have a combobox with a value list of 4 items. My code needs to know the number of items in that combobox. How can I use VBA to get the number of items in a combobox? TIA --
0
by: tupolev | last post by:
Hi, I already post this item but now I know whats wrong: I want to allow the user to edit the items in a combobox. The problem is that the textchange event works just one time (for the first...
10
by: Steve Bostedor | last post by:
Does anyone have an example of how to file.copy as another user? Do I create a new thread as another user? How is that done? Thanks!
0
by: Pramod Kadur | last post by:
I have a combobox which has a list of items displayed by default. Based on selection of an item in first combobox, i need to display the related items in my second combobox, so i need to remove those...
1
by: mawenb | last post by:
I have a comboBox. evevry time I selected an item in the comboBox, the dropdownlist resized. It flashed before disapeared. In my code, I handled the comboBox SelectionChangeSubmitted event, and ...
1
by: vishnu2008 | last post by:
I am using MS Access (frontend), VB 6.0 (code) and SQL Server (DB) now. I have a combobox and textbox. I need to select multiple items from combobox which should be displayed in textbox. Items should...
5
by: Kevinp | last post by:
I've spent the last four hours Google searching for a way to disable items in a Combobox. I found one example in C++ which I can't get to work and another in C# that I couldn't get to work either....
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.