Kiran SK
Kiran SK

Reputation: 19

How to make value carry forward while looping?

Thank you for your time spending at my question. My issue was, I was trying to make some records into BLACK & GRAY color based on some condition. But while doing, I am able to make BLACK color for all the records but leaving last record. Hence, I am missing to color-out the last record. I want to make all the records to BLACK in color. Here is my code. Please find it.

     For K = 1 To lvMergeGroup.ListItems.Count
     If ptrDataItem.ValidTo = "xxxxxxxxxxx" And ptrDataItem.StatusIndicator = "A" And ptrDataItem.UpdateTimeStamp = "xxxxxxxxxxx" Then 
             lvMergeGroup.ListItems.Item(K).ForeColor = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black))  
     Else
             lvMergeGroup.ListItems.Item(K).ForeColor = System.Convert.ToUInt32(System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Gray))
     End If
     Next K

Upvotes: 0

Views: 103

Answers (1)

dmshow
dmshow

Reputation: 121

Change your loop to

K = 0 To lvMergeGroup.ListItems.Count -1

Collections start at position 0

You could also use a for each loop, which will also give you access to each item individually.

For Each item In lvMergeGroup.ListItems
'code for 'item'
Next

Upvotes: 1

Related Questions