Hi,

I have a windows form, in C#. It has a ListView on it. For a couple of
reasons I now need to be have multiple sets of Data that can be dynamically
Copied into and out of the ListView. But I'm having realy trouble with
it....and feeling pretty frustrated.

I firstly tried copying over listView.Items - which is ok to read out of,
but its a read only property and can be copied back over.

Also tried listView.Items.CopyTo (lviArray) and tried a
listView2.Items.AddRange (lviArray), but I get an exception about data
already existing else where either remove it first or clone it. Tried
cloning it but that doesn't seem to work either.


Feel I am missing something. Any help would be appreciated.

Thanks,
Laura

RE: ListView & Copying of by John

John
Thu Feb 17 15:25:03 CST 2005

A ListView.ListViewItemCollection that contains all the items in the ListView
control.

Why not create a few of these Collections and assign them at runtime?

You could clear() the ListView items first, then use a foreach loop to
iterate through the substitute ListViewItemCollection calling the
ListView.Items.Add() method for each item to be placed into the ListView.



"laurmo" wrote:

> Hi,
>
> I have a windows form, in C#. It has a ListView on it. For a couple of
> reasons I now need to be have multiple sets of Data that can be dynamically
> Copied into and out of the ListView. But I'm having realy trouble with
> it....and feeling pretty frustrated.
>
> I firstly tried copying over listView.Items - which is ok to read out of,
> but its a read only property and can be copied back over.
>
> Also tried listView.Items.CopyTo (lviArray) and tried a
> listView2.Items.AddRange (lviArray), but I get an exception about data
> already existing else where either remove it first or clone it. Tried
> cloning it but that doesn't seem to work either.
>
>
> Feel I am missing something. Any help would be appreciated.
>
> Thanks,
> Laura

Re: ListView & Copying of by cody

cody
Fri Feb 18 08:14:16 CST 2005

Why not holding multiple listviews in memory? You only show one at a time
and you can then simply exchange them which is extremely fast.

"laurmo" <laurmo@discussions.microsoft.com> schrieb im Newsbeitrag
news:3FCBCCD7-0595-4BCD-8D72-DD6325D31B82@microsoft.com...
> Hi,
>
> I have a windows form, in C#. It has a ListView on it. For a couple of
> reasons I now need to be have multiple sets of Data that can be
dynamically
> Copied into and out of the ListView. But I'm having realy trouble with
> it....and feeling pretty frustrated.
>
> I firstly tried copying over listView.Items - which is ok to read out of,
> but its a read only property and can be copied back over.
>
> Also tried listView.Items.CopyTo (lviArray) and tried a
> listView2.Items.AddRange (lviArray), but I get an exception about data
> already existing else where either remove it first or clone it. Tried
> cloning it but that doesn't seem to work either.
>
>
> Feel I am missing something. Any help would be appreciated.
>
> Thanks,
> Laura



RE: ListView & Copying of by laurmo

laurmo
Fri Feb 18 10:01:10 CST 2005

"John" wrote:

> A ListView.ListViewItemCollection that contains all the items in the ListView
> control.
>
> Why not create a few of these Collections and assign them at runtime?

This doesn't work, unless I'm using it wrongly. When you construct a
ListViewItemCollection is takes a single parameter of a ListView, which is
its owner.

Basically it then turns out that the ListViewItemCollection is then just a
reference to the ListView.Items data and any operation done on one is
reflected on the other.

>
> You could clear() the ListView items first, then use a foreach loop to
> iterate through the substitute ListViewItemCollection calling the
> ListView.Items.Add() method for each item to be placed into the ListView.
>
>

So Clear ( ) on the ListView results in the clear of the
ListViewItemCollection.

I think I will have to duplicate the ListView objects and swap then in and
out at runtime as Cody suggested. But this is a pretty poor solution - I
thought I just wanted to do something simple with the data!

Thanks for the help, good to know I wasn't missing anything obvious.