farmer <an*******@hotmail.vom> scripsit:
I need to populate a listbox of other listview with selected listview
items.although the following code works perfecty I want to use an
Array (for various reasons)
for Each ListItem In listview1.ListItems
If ListItem.Checked = True Then
listbox1.AddItem ListItem.Text
next
So I'm trying to fill an array with listview items. (I need only the
first Item)
Here is The code
Dim varrSel()
Dim i As Integer
Dim cnt As Integer
For Each ListItem In listview1.ListItems
If ListItem.Checked = True Then
cnt = cnt + 1
ReDim Preserve varrSel(1 To cnt)
varrSel(cnt) = ListItem.Text
End If
Next
listbox1.List = varrSel
The only problem is that I can't get it to work
In VB.NET, arrays have indices 0, ..., n. To create an array with n
elements, you can use 'ReDim Preserve varrSel(n - 1)'. Notice that
changing the number of elements in an array is a very costly process
(every time you do that the array will be copied to a new array and the
old array will be deleted). You can use an 'ArrayList' instead of the
array to get a better performance.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>