PC Review


Reply
Thread Tools Rate Thread

Copy items to another combobox?

 
 
james
Guest
Posts: n/a
 
      3rd Jan 2007
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.

 
Reply With Quote
 
 
 
 
DeveloperX
Guest
Posts: n/a
 
      3rd Jan 2007
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.


 
Reply With Quote
 
james
Guest
Posts: n/a
 
      3rd Jan 2007

"DeveloperX" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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?

 
Reply With Quote
 
DeveloperX
Guest
Posts: n/a
 
      3rd Jan 2007
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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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?


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox items based on choice in previous combobox Slim Slender Microsoft Excel Programming 0 2nd Aug 2011 03:52 AM
ComboBox.Items.Clear() causes the selection of Text inside the edit of the ComboBox Nomasnd Microsoft Dot NET Framework Forms 1 27th Sep 2006 06:32 PM
Combobox items determined by the selection in another combobox =?Utf-8?B?QWxlcmlvbg==?= Microsoft Excel Programming 2 13th Sep 2006 01:07 PM
How can I copy a Combobox with all items ? hans.domian@de.man-mn.com Microsoft Excel Programming 6 7th Aug 2006 12:28 PM
Move Items/copy items dialog box shows up when it shouldn't Charley Windows XP General 3 17th Nov 2005 04:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:23 AM.