-
July 24th, 2014, 10:01 PM
#1
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
-
July 24th, 2014, 11:40 PM
#2
Re: Simple question on updating List items
What's the problem? What kind of list?
-
July 25th, 2014, 10:23 AM
#3
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
-
July 25th, 2014, 12:37 PM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|