Ice725 Posted May 6, 2004 Posted May 6, 2004 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? Quote
JABE Posted May 6, 2004 Posted May 6, 2004 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. Quote
Ice725 Posted May 6, 2004 Author Posted May 6, 2004 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 Quote
JABE Posted May 7, 2004 Posted May 7, 2004 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.