1 Replies - 310 Views - Last Post: 28 March 2012 - 05:42 AM Rate Topic: -----

#1 cj777  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 118
  • Joined: 03-March 12

listview error in clicking

Posted 28 March 2012 - 05:19 AM

i have a listview that when i select the items on it, then the id would go to a lable but when i click for another item with different id it has an error here is my code:
  Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        Me.lblpid.Text = Me.ListView1.SelectedItems(0).SubItems(0).Text
    End Sub
here is my error:InvalidArgument=Value of '0' is not valid for 'index'. Parameter name: index

Is This A Good Question/Topic? 0
  • +

Replies To: listview error in clicking

#2 damdimdum  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 42
  • Joined: 20-February 12

Re: listview error in clicking

Posted 28 March 2012 - 05:41 AM

try
 Private Sub ListView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ListView1.KeyDown
        If e.KeyCode = Keys.Enter Then
            If Not ListView1.SelectedItems.Count = 0 Then
                With ListView1.SelectedItems(0)
                    lblpid.Text = ListView1.SelectedItems.Item(0).Text
                End With               
            End If
        End If
    End Sub

This post has been edited by damdimdum: 28 March 2012 - 05:42 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1