[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

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
0
robertjmackay
Asked:
robertjmackay
1 Solution
 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now