Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

issues with listview subitem update

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
US
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.

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.
 

Why are you using "z + 1" in lines like this:

lstServers.Items(z).SubItems(z + 1).Text = "Success"



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
jebenson,

I figured it out last night. you are dead on. that's what happens when someone codes too late at night I guess. i fixed it last night. i removed the z+1 and just used the column # and wham it worked. still did not really like the list view. so i converted to a DataGridView. much nicer.

Thanks.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top