I'm trying to load a listview control that contains two columns. Here is my current code:
lvwWorkbooks = the name of the listview control on the form.
dtNatt = the data table
When I run this code, I receive an error message in the message box but when I click "Ok" the form appears with the listview loaded correctly.
The error message I get is 'System.ArgumentException: Cannot add or insert the item 'drive:\directory\filename' in more than one place. You must first remove it from its current location or clone it.'.
I've never tried to use a listview in DotNet so please be gentle. I tried the code in Help but that didn't work.
Even though what I have appears to work, just knowing an error is being generated will drive me nuts.
Would someone please point me in the right direction? There has to be a way to do this without throwing an error and I really want to learn to do this the correct way.
VB.NET:
Try
Dim lvwCollection As New ListView.ListViewItemCollection(Me.lvwWorkbooks)
For Each row As DataRow In dtNatt.Rows
Dim nuItem As New ListViewItem(row.Item("nattsPath").ToString(), 0)
If Not (IsNothing(row.Item("nattsRegion").ToString())) Then
nuItem.SubItems.Add(row.Item("nattsRegion").ToString())
Else
nuItem.SubItems.Add(" ")
End If
lvwCollection.Add(nuItem)
nuItem = Nothing
Next
Me.lvwWorkbooks.Items.AddRange(lvwCollection)
Catch ex As Exception
MsgBox(ex.ToString())
End Try
dtNatt = the data table
When I run this code, I receive an error message in the message box but when I click "Ok" the form appears with the listview loaded correctly.
The error message I get is 'System.ArgumentException: Cannot add or insert the item 'drive:\directory\filename' in more than one place. You must first remove it from its current location or clone it.'.
I've never tried to use a listview in DotNet so please be gentle. I tried the code in Help but that didn't work.
Even though what I have appears to work, just knowing an error is being generated will drive me nuts.
Would someone please point me in the right direction? There has to be a way to do this without throwing an error and I really want to learn to do this the correct way.
Last edited: