Jackles
Jackles

Reputation: 13

InvalidArgument=Value of '5' is not valid for 'index'.

Well, merry christmas all!

I am having trouble with the following whilst writing my chatroom program. I am adding an item to a listview, but when i try to add text to the last subitem, I get the error InvalidArgument=Value of '5' is not valid for 'index'.

I have done the following:

msgbox(listview1.subitems.count())

and that returns 5, so I assume that means I have a total of 6 columns (the counting begins from 0 - 5 not 1 - 5.

What could be the problem? The rest of the code is:

Sub AddClient(ByVal client As connection, ByVal strings() As String)
    Dim l As New ListViewItem(strings)
    l.ImageIndex = GetFlag(strings(1).ToLower)
    l.Tag = client
    numcon1.Text += 1
    l.SubItems(5).Text = "test phrase"
    l.SubItems(4).Text = strings(7)
    addtoconsole(strings(3) & " ~ " & strings(1) & " Has Connected.")
    ListView1.Items.Add(l)
    If audiocon = "True" Then
        My.Computer.Audio.Play("newuser.wav", AudioPlayMode.Background)
    Else
    End If
    If notifcon = "True" Then
        NotifyIcon1.ShowBalloonTip(3000, "A friend is online!", strings(3) & " ~ " & strings(1), ToolTipIcon.Info)
    End If
End Sub

thanks so much!

Upvotes: 1

Views: 4665

Answers (1)

Oded
Oded

Reputation: 499062

that returns 5, so I assume that means I have a total of 6 columns (the counting begins from 0 - 5 not 1 - 5.

No. It means 5 columns in total. Starting with index 0 and ending with index 4.

Upvotes: 1

Related Questions