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

Posted on 2004-11-02
Last Modified: 2010-04-23
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

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

End Sub
Question by:robertjmackay
    1 Comment
    LVL 27

    Accepted Solution

    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
        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
                          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
              Cursor.Current = Cursors.Default
        End Sub

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now