problem copying columns
I've got a couple of listboxes which the user can move items from one to the other. When they're done moving the items, which are column names from a datatable, I want to show only the columns which have names in the first list box.
the list box items look like this:
01 surname
02 firstname
03 initials
So I cut off the first part of the listbox item to get the column index
Early on in the code I populate a datatable called dt and use the column names to fill the listbox. The part I've described above all seems to work fine.
This bit doesn't:
Code:
Dim newdt As New DataTable()
For i = 0 To ListBox1.Items.Count() - 1
Dim mystr As String = ListBox1.Items(i).ToString().Substring(0, 2) 'here I'm cutting the index off the front of the string
Dim myint As Short = Val(mystr) 'turning the index into a value
newdt.Columns.Add(dt.Columns(myint))
Next
I get this error:
An unhandled exception of type 'System.ArgumentException' occurred in system.data.dll
Additional information: Column 'Surname' already belongs to another DataTable.
I'm using .NET Framework 3.5
I'm planning to be spontaneous tomorrow