Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

When I try and run my program, I get a nasty error message that says the following:

 

 

An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

 

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

 

 

I know WHERE the problem is, but don't know how to solve it... I have a for loop when sets all the propertys for each ListView item in my Array. If I take out the following line, it works fine, but if I try and add the column headers, I get the error message above...

 

this.lstTeam[x].Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {this.columnHeader1, ........... all the way to this.columnHeader9});

 

Another catch is if I just add the 1st ListView in my Array, I am able to add the column headers. It barf's on the lstTeam[1] element...

 

Any Help?

Posted
Are you attempting to add this.columnHeader1 thru this.columnHeader9 to more than one listview? Basing on the error msg, I think that's causing the problem. And also as per the error msg, "You must first remove it from its current location or clone it." Meaning you can't add the same columnheader to more than 1 listview control.
Posted
Yes, I was trying to add columnHeader1 to columnHeader9 in EACH of my ListView Arrays. I dont understand why you can't do that, but I converted them into array's and it works now. Thanks
Posted

I was trying to add columnHeader1 to columnHeader9 in EACH of my ListView Arrays. I dont understand why you can't do that

 

Since references are passed around during assignment, an operation to one reference (e.g., to ListView1.ColumnHeader1) will affect other references (e.g., ListView2.ColumnHeader2) and I guess this is rarely an intended effect. It's the same behavior-by-design for a Datatable w/c can't belong to more than one Dataset.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...