Hi there,

I am having problem trying to retrieve the data from ListView the 2nd time round. It works the first time I clicked on the Line Item and when I clicked on another line item it gave me this error message :-
"Specific argument ws out of the range of valid values. Parameter name : Index

Here are the sample scipts:-

Private Sub ListClient_SelectedIndexChanged( _
ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListClient.SelectedIndexChanged

Dim intIndex As Integer

Try
With ListClient

intIndex = .SelectedIndices(0)

lngPClientId = .Items(intIndex).Text
Me.lblClientId.Text = lngPClientId
txtClientName.Text = .Items(intIndex).SubItems(1).Text
txtAcctMgr.Text = .Items(intIndex).SubItems(2).Text

intIndex = 0
End With

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub

Please help me. Thanks

Have a Good Day,

Cheers,
Lennie

Attachments ListView.JPG 31.56 KB

hi ,
When you select the first row there is no problem coz the event fires once ok, but the problem accurse when you select other row coz the event (which is ListView1_SelectedIndexChanged) fires twice once for deselect the first row and the other for select the second row. So the message "Specific argument was out of the range of valid values. Parameter name: Index " show because deselect the first row you chosen. I hope I could explain well :cheesy:

Any way the solution is by adding if statement before the retrieve of the list row information

If ListClient.SelectedItems.Count = 0 Then Exit Sub
       Try
            With ListClient

                intIndex = .SelectedIndices(0)

                lngPClientId = .Items(intIndex).Text
                Me.lblClientId.Text = lngPClientId
                txtClientName.Text = .Items(intIndex).SubItems(1).Text
                txtAcctMgr.Text = .Items(intIndex).SubItems(2).Text

                intIndex = 0
            End With

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

hi ,
When you select the first row there is no problem coz the event fires once ok, but the problem accurse when you select other row coz the event (which is ListView1_SelectedIndexChanged) fires twice once for deselect the first row and the other for select the second row. So the message "Specific argument was out of the range of valid values. Parameter name: Index " show because deselect the first row you chosen. I hope I could explain well :cheesy:

Any way the solution is by adding if statement before the retrieve of the list row information

If ListClient.SelectedItems.Count = 0 Then Exit Sub
       Try
            With ListClient

                intIndex = .SelectedIndices(0)

                lngPClientId = .Items(intIndex).Text
                Me.lblClientId.Text = lngPClientId
                txtClientName.Text = .Items(intIndex).SubItems(1).Text
                txtAcctMgr.Text = .Items(intIndex).SubItems(2).Text

                intIndex = 0
            End With

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

Hi Manal,
Thanks for taking time to explain the situation to me. Now, I understand why I am getting those error message. And also thanks for the sample scripts.

Cheers,
Lennie

This article has been dead for over six months. Start a new discussion instead.