Simple question on updating List items
I'm trying to find a simple way to update the items in a list. When using For...Each the items do not actually get updated. See the following code...
Private Structure test
Dim iNum As Integer
Dim strStr As String
End Structure
Private oTest As New List(Of test)
Dim newTest = New test
newTest.iNum = 1
newTest.strStr = "a"
oTest.Add(newTest)
For Each testItem As test In oTest
testItem.iNum = 2
Next
The list hasn't updated at this point. How can the list be modified?
Thanks
Re: Simple question on updating List items
What's the problem? What kind of list?
Re: Simple question on updating List items
The problem is that while iterating through a generic list, updating the iterated member does not actually update the list value itself. Please see the example code.
Thanks
Re: Simple question on updating List items
Something BACKWARDS is what you want.
Code:
Option Explicit
Private Sub Command1_Click()
Dim s%, x As Integer
s = List1.TopIndex
If s < List1.ListCount - 6 Then
List1.TopIndex = List1.TopIndex + 5
Else
List1.TopIndex = 0
End If
For x = 0 To List1.ListCount - 1
' Reverse the parms
If List1.Selected(x) = True Then
List1.Selected(x) = False
End If
Next x
End Sub
Private Sub Form_Load()
Dim x%
For x = 0 To 15
List1.AddItem x + 1
Next x
End Sub