469,575 Members | 1,206 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,575 developers. It's quick & easy.

Copy Listview to Listview

I have two Listview controls on the stage:
lv_Files
lv_SelectedFiles

I have a function that copies the selected items from lv_Files to
lv_SelectedFiles.
I am currently using a loop on the selected indices to copy. This is quite a
slow process when there are a lot of entries selected in lv_Files.

There is also a Copy All button that first selects all indices, then loops
through lv_Files, individually copying to lv_SelectedFiles.

Is there a method to perform this copy without the loop? Some faster
implementation? I have not been able to find any documention or code
examples for such.
Nov 16 '05 #1
3 16646
Hi there... try this

object[] dest = new object[listBox1.Items.Count];
listBox1.Items.CopyTo(dest, 0);
listBox2.Items.AddRange(dest);

Regards,
--
Angel J. HernŠndez M.
MCSD

"CaffeineRush" <gr******@swbell.net> escribiů en el mensaje
news:3G*****************@newssvr22.news.prodigy.co m...
I have two Listview controls on the stage:
lv_Files
lv_SelectedFiles

I have a function that copies the selected items from lv_Files to
lv_SelectedFiles.
I am currently using a loop on the selected indices to copy. This is quite a slow process when there are a lot of entries selected in lv_Files.

There is also a Copy All button that first selects all indices, then loops
through lv_Files, individually copying to lv_SelectedFiles.

Is there a method to perform this copy without the loop? Some faster
implementation? I have not been able to find any documention or code
examples for such.

Nov 16 '05 #2
I got the following to compile:

ListViewItem[] dest = new ListViewItem[lv_Files.Items.Count];
// object[] dest = new object[lv_Files.Items.Count];
lv_Files.Items.CopyTo(dest, 0);
lv_SelectedFiles.Items.AddRange(dest);

but get the following System.ArgumentException error in system.windows.forms.dll:

Additional information: Cannot add or insert the item 'filename.jpg' in more than one place. You must first remove it from its current location or clone it.

Any ideas? Thanks!

"Angel J. HernŠndez" <an**********@hotmail.com> wrote in message news:u5**************@tk2msftngp13.phx.gbl...
Hi there... try this

object[] dest = new object[listBox1.Items.Count];
listBox1.Items.CopyTo(dest, 0);
listBox2.Items.AddRange(dest);

Regards,


--
Angel J. HernŠndez M.
MCSD



"CaffeineRush" <gr******@swbell.net> escribiů en el mensaje
news:3G*****************@newssvr22.news.prodigy.co m...
I have two Listview controls on the stage:
lv_Files
lv_SelectedFiles

I have a function that copies the selected items from lv_Files to
lv_SelectedFiles.
I am currently using a loop on the selected indices to copy. This is quite

a
slow process when there are a lot of entries selected in lv_Files.

There is also a Copy All button that first selects all indices, then loops
through lv_Files, individually copying to lv_SelectedFiles.

Is there a method to perform this copy without the loop? Some faster
implementation? I have not been able to find any documention or code
examples for such.


Nov 16 '05 #3
Hi,

I believe that "listBox2.Items.AddRange(...)" is key for
your performance goal.

And i think that loop (with "Clone()" of items) over your
"listBox1.SelectedItems" should be solution.

Cheers!

Marcin
I got the following to compile:

ListViewItem[] dest = new ListViewItem[lv_Files.Items.Count];
// object[] dest = new object[lv_Files.Items.Count];
lv_Files.Items.CopyTo(dest, 0);
lv_SelectedFiles.Items.AddRange(dest);

but get the following System.ArgumentException error in
system.windows.forms.dll:

Additional information: Cannot add or insert the item 'filename.jpg' in
more than one place. You must first remove it from its current location
or clone it.

Any ideas? Thanks!

"Angel J. Hern√°ndez" <an**********@hotmail.com
<mailto:an**********@hotmail.com>> wrote in message
news:u5**************@tk2msftngp13.phx.gbl...
> Hi there... try this
>
> object[] dest = new object[listBox1.Items.Count];
> listBox1.Items.CopyTo(dest, 0);
> listBox2.Items.AddRange(dest);
>
> Regards,
>
>
> --
> Angel J. Hern√°ndez M.
> MCSD
>
>
>
> "CaffeineRush" <gr******@swbell.net <mailto:gr******@swbell.net>>

escribió en el mensaje
> news:3G*****************@newssvr22.news.prodigy.co m...
> > I have two Listview controls on the stage:
> > lv_Files
> > lv_SelectedFiles
> >
> > I have a function that copies the selected items from lv_Files to
> > lv_SelectedFiles.
> > I am currently using a loop on the selected indices to copy. This is quite
> a
> > slow process when there are a lot of entries selected in lv_Files.
> >
> > There is also a Copy All button that first selects all indices,

then loops > > through lv_Files, individually copying to lv_SelectedFiles.
> >
> > Is there a method to perform this copy without the loop? Some faster
> > implementation? I have not been able to find any documention or code
> > examples for such.
> >
> >

>
>

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Anushya | last post: by
1 post views Thread by Dragan Ristic | last post: by
4 posts views Thread by Brian Gaze | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.