listview - clikc on row to retyrieve value of the selected item

Below is code that retrieves the text of the selected item.  
When I clik on another row, it bombs with an out of bounds error.  Through debug, i have learned that rmac_listview.selectedIndices.count = 0 after the second row is selected ... like its not recognizing the second row as being selected.  

I have tried this with multi-row selection on and off and it doesn;t seem to make a difference.

What I want to do is have the user double clik on a row, pickup a few values and launch a new form, only one row


Private Sub rmac_listview_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
rmac_listview.SelectedIndexChanged

Dim selected_counter = rmac_listview.SelectedIndices.Count
Dim selected_record = rmac_listview.SelectedIndices(0)
Dim temp = rmac_listview.Items(selected_record).Text

End Sub
robertjmackayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

planoczCommented:
Here is a sample code to use ...


dim iCounterID  as short


Private Sub rmac_listview_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles rmac_listview.DoubleClick
       
        rmac_listview.MultiSelect = False
        ListNames()
        Me.Close()
    End Sub

  Private Sub ListNames()
        Dim i As Short

        If rmac_listview.SelectedItems.Count = 0 Then Exit Sub
        btnOK.Enabled = True
        ReDim arrList(rmac_listview.SelectedItems.Count - 1)
        'Gobal counter for single and muti. hand picked numbers (customers)
        iCounterID = rmac_listview.SelectedItems.Count
        'Make Array for Regular Addresses Per Customer List
        For i = 0 To rmac_listview.SelectedItems.Count - 1
            Try
                      Textbox1.text = rmac_listview.SelectedItems.Item(i).Text            '<------ First Column
                      Textbox2.text = rmac_listview.SelectedItems.Item(i).SubItems(1).Text   '<----- Second Column
               Catch Exp As SystemException
                MsgBox("Button Click Error", MsgBoxStyle.Critical, "Read ListView Error")
            Catch Exp As Exception
                MsgBox(Exp.Message, MsgBoxStyle.Critical, "General Error")
            End Try
            Cursor.Current = Cursors.Default
        Next
          Cursor.Current = Cursors.Default
    End Sub

'If you use multi Select you will need to change the Texbox1.text output
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.