taxgurl
asked on
ListBox SelectedItems.CopyTo
I'm trying to use this function to copy all of the selected items in my list box to an array to be used for other purposes. I get an error "Object cannot be stored in an array of this type" with the following code. However when I look at the definition of the CopyTo function, it says that it take 2 arguments (System.Array and Index).
Any ideas on how I can do this?
Dim Groups(lstGroupCode.Select edItems.Co unt) As System.Array
lstGroupCode.SelectedItems .CopyTo(Gr oups, 0)
Any ideas on how I can do this?
Dim Groups(lstGroupCode.Select
lstGroupCode.SelectedItems
ASKER
thanks, I tried that as well, but that returns an object of type dataRowView..... I want an array.
what is the datasource for your listbox?
ASKER
it's a dataSet
Did you try:
Dim Groups(lstGroupCode.Select edItems.Co unt) As String
lstGroupCode.SelectedItems .CopyTo(Gr oups, 0)
Dim Groups(lstGroupCode.Select
lstGroupCode.SelectedItems
ASKER
Yep, tried that also - I don't remember the result off hand, but I got an error on that as well.
It's very strange, b'cause this code works fine:
Dim arr(ListBox1.SelectedItems .Count) As String
ListBox1.SelectedItems.Cop yTo(arr, 0)
Dim str As String = ""
For i As Integer = 0 To UBound(arr) - 1
str += arr(i) & vbCrLf
Next
MsgBox(str)
Dim arr(ListBox1.SelectedItems
ListBox1.SelectedItems.Cop
Dim str As String = ""
For i As Integer = 0 To UBound(arr) - 1
str += arr(i) & vbCrLf
Next
MsgBox(str)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much BriCrowe, this solution works perfect. And thanks so much for your very quick responses (which is why I valued this question so high).
lstGroupCode.SelectedItems