Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / January 2005

Tip: Looking for answers? Try searching our database.

Strange ListView problem (using multiple ListView's on one form)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff Slapp - 31 Dec 2004 15:56 GMT
I am experiencing a strange problem with my ListViews. I have two listviews
on a form. One of the listview contains a master set of data and the other
will contain a subset of that data.

I have instantiated two separate listviews and for some reason when ever I
copy an item from one list view to another (using a simple ArrayList as my
temporary work area on the subset data), I get an error as follows:

An unhandled exception of type 'System.ArgumentException' occurred in
system.windows.forms.dll
Additional information: Cannot add or insert the item 'testitem' in more
than one place. You must first remove it from its current location or clone
it.

But, If I perform a listview.Items.Clear() before moving data into the
second listview....everything is fine. But I want the data in both
places.......

I thought this could have been some sort of reference issue....but since I
have two separate instances of ListView I don't see how....but at this point
I am stuck.

Any help would be appreciated. Thank you!

----------------------------------------------------
Jeff Slapp
Fairway Consulting Group, Inc.
Ft Lauderdale, FL
www.fcgroup.us
----------------------------------------------------
Carlos J. Quintero [.NET MVP] - 03 Jan 2005 11:50 GMT
Hi,

To copy a ListViewItem from ListView1 to ListView2, rather than using:

   ListView2.Items.Add(ListView1.Items.Item(0))

which causes the exception that you mention, use this instead:

   ListView2.Items.Add(DirectCast(ListView1.Items.Item(0).Clone,
ListViewItem))

since a single instance of a ListViewItem can not belong to 2 listviews, you
need a clone.

Signature

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code and design much faster.
http://www.mztools.com

>I am experiencing a strange problem with my ListViews. I have two listviews
>on a form. One of the listview contains a master set of data and the other
[quoted text clipped - 26 lines]
> www.fcgroup.us
> ----------------------------------------------------
Jeff Slapp - 03 Jan 2005 15:59 GMT
That worked. Thanks!

> Hi,
>
[quoted text clipped - 40 lines]
>> www.fcgroup.us
>> ----------------------------------------------------

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.