472,784 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to copy one listview to another. Hopefully this can help someone ;-)

Hi guys,
I stuffed around with this for a whole day, searching the groups
and trying different methods. So when I finally came up with a solution
I thought I would share it, as it could save someone all the stuffing
round I had to do. Now I don't know if this will solve everyone's
listview copy situation, but it worked for me.

Here is the code:

ListViewItems[] LVIARRY_CopiedListViewItems = new
ListViewItems[LV_FirstListView.Items.Count];

for (int INT_Count=0; INT_Count < LVIARRY_CopiedListViewItems.Length;
INT_Count++)
{
LVIARRY_CopiedListViewItems[INT_Count] =
(ListViewItem)LV_FirstListView.Items[INT_Count].Clone();
}

LV_SecondListView.Items.AddRange(LVIARRY_CopiedLis tViewItems);

Scott.

Nov 17 '05 #1
2 4582
did you try the Array.Copy() method work on this? Or does this create
a new instance of an array with references to the original ListItems?

Nov 17 '05 #2
James,
I did try that method, but I had the same problem as the poster
called "CaffeineRush" in this post:
---------------------------------------------------
http://groups.google.com/group/micro...294ffc72f62442

I go the same:
---------------------------------------------------
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.
---------------------------------------------------
After a bit more research I then found this thread:
---------------------------------------------------
http://groups.google.com/group/micro...otnet.*&rnum=2

See where the poster "laurmo" says:
---------------------------------------------------
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.
---------------------------------------------------

I am open to new ideas however?

Scott.

ja*********@gmail.com wrote:
did you try the Array.Copy() method work on this? Or does this create
a new instance of an array with references to the original ListItems?


Nov 17 '05 #3

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

Similar topics

0
by: MikeY | last post by:
Hopefully someone can help, I have a listview box where I display my desired files. I single click on the desired file to be renamed and I rename it with a new name. My problem arises when the...
3
by: MikeY | last post by:
Hopefully someone can help me on this. I am using C#, making Windows forms. I have created a listView with checkbox's. I have enabled the checkboxes under the properties, and all the data,...
1
by: MikeY | last post by:
Hopefully someone can help, I have a listview box where I display my desired files. I single click on the desired file to be renamed and I rename it with a new name. My problem arises when the...
9
by: Devron Blatchford | last post by:
Hi there, Just wondering if I change the back and fore colour of a listview item when the mouse hovers over it? I want to overide the default windows colour. Can someone please tell me how to...
6
by: Beginner | last post by:
Hi, I'm trying to populate a TreeView from an existing and filled in ListView (lvwBuild). lvwBuild is a basic two column listview which can have any number of rows. I would like the first...
2
by: Tim.Geiges | last post by:
This seems like ti should be very simple but I am sort of a newb and this one is killing me I am just trying to copy all the items that are checked in listView2 over to listView1 when a button is...
4
by: Pucca | last post by:
How can I tell a mouse right clicks over a listview item that's in a container panel. I only want to display a popup menu if the user right click the mouse over an item on the Listview. I don't...
1
by: MikeY | last post by:
Hi Everyone, I am trying to ensure displayed items at the top most portion of my ListView when being added to my ListView, no matter where the items are being added with in the listview. So that...
1
by: BeckyBair | last post by:
Currently I have a program form that has 2 listviews on it. It is able to copy one item from one listview to another. Now the users want to be able to copy several at once from one listview and...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.