Lloyd Sheen said:
I tried this and the C# version would provide an incremented value for
each listviewitem created. So you would expect a collection of
listviewitems where the imageIndex would start at 1 and increment for each
item.
When you try the code in VB (and I have no idea why) you end up with a
list of listviewitems and each has an imageIndex of 2. If I change the
code to i +=2 then the items have an imageIndex of 3. It seems that the
final increment is what is used as if the value is not created until used.
LS
Ok I think you can use a function to do the incrementing:
Dim Persons() As String = {"Him", "Her", "Them"}
Dim ii As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim tst = From t In Persons _
Select New ListViewItem(t, GiveMeAnInt(t))
Dim i As Integer = tst.Count
Dim tl As List(Of ListViewItem) = tst.ToList
End Sub
Private Function GiveMeAnInt(ByVal tmp As String) As Integer
ii += 1
Return ii
End Function
Once again though the imageIndex values are in fact 4,5,6 which I think
confirms that somehow the values are being put in at a time other than what
I would think is correct. Linq has its values but I don't think that in
the case of VB that this works very well.
Tracing the call to GiveMeAnInt shows 6 calls. Seems like the .ToList
recalls the values so if you want to create the list you would have to put
an ii=0 prior to the .ToList call. My last iteration also removed the need
to have a parameter to the GiveMeAnInt. All in all quite a kludge.
Lloyd Sheen