I have items in a listview with 4 columns and i am having issues with it updating correctly. it starts to update fine in the first row, but when it goes to the other rows I get an error of:
InvalidArgument=Value of '4' is not valid for 'index'. Parameter name: index
Not sure why. It's fairly simple. I have a loop going that does a continuous ping on the servernames in the list view and other columns to log, Reply Status, Response Time and Last Timeout Date/Time.
I also noticed when it cycles to the next row before the error that it does not update the correct subitem, instead of updating subitem 1 it will update 2 instead with what is supposed to go in 1.
my code is as follows.
InvalidArgument=Value of '4' is not valid for 'index'. Parameter name: index
Not sure why. It's fairly simple. I have a loop going that does a continuous ping on the servernames in the list view and other columns to log, Reply Status, Response Time and Last Timeout Date/Time.
I also noticed when it cycles to the next row before the error that it does not update the correct subitem, instead of updating subitem 1 it will update 2 instead with what is supposed to go in 1.
Code:
Dim lvi, z As Integer
Dim servers As String
lvi = lstServers.Items.Count - 1
Do Until bCancel = True
For z = 0 To lvi
servers = lstServers.Items(z).Text
MultiPingSystem(servers)
Application.DoEvents()
If bCancel Then
bCancel = True
lstServers.BackColor = Color.White
MsgBox("Pinging Stopped")
Exit For
End If
If pingresults = "Success" Then
If lstServers.Items(z).SubItems(z + 1).Text = "Success" Or _
lstServers.Items(z).SubItems(z + 1).Text = "Not Pinged" Then
lstServers.Items(z).BackColor = Color.GreenYellow
lstServers.Items(z).SubItems(z + 1).Text = "Success"
lstServers.Items(z).SubItems(z + 2).Text = roundtriptime
lstServers.Items(z).SubItems(z + 3).Text = "No Timeout"
Else
lstServers.Items(z).SubItems(z + 1).Text = "No Reply"
lstServers.Items(z).SubItems(z + 2).Text = "Timeout"
lstServers.Items(z).SubItems(z + 3).Text = currentdt
End If
Else
lstServers.Items(z).BackColor = Color.GreenYellow
lstServers.Items(z).SubItems.Add("No Reply")
lstServers.Refresh()
lstServers.Items(z).SubItems.Add("Timed Out")
lstServers.Refresh()
lstServers.Items(z).SubItems.Add(currentdt)
End If
Next
Loop
my code is as follows.