How do i get the SelectedItem or SelectedIndex of ListView in vb.net

前端 未结 7 1902
闹比i
闹比i 2020-12-10 13:04

As you know by question that what I want. I was using listbox. In ListBox we can get selected item by a simple line of code: listbox1.SelectedItem.

相关标签:
7条回答
  • 2020-12-10 13:40
    Private Sub ListView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.Click
            Dim tt As String
            tt = ListView1.SelectedItems.Item(0).SubItems(1).Text
            TextBox1.Text = tt.ToString
    End Sub
    
    0 讨论(0)
  • 2020-12-10 13:46

    Please Try This for Getting column Index

    Private Sub lvDetail_MouseMove(sender As Object, e As MouseEventArgs) Handles lvDetail.MouseClick
    
        Dim info As ListViewHitTestInfo = lvDetail.HitTest(e.X, e.Y)
        Dim rowIndex As Integer = lvDetail.FocusedItem.Index
        lvDetail.Items(rowIndex).Selected = True
        Dim xTxt = info.SubItem.Text
        For i = 0 To lvDetail.Columns.Count - 1
            If lvDetail.SelectedItems(0).SubItems(i).Text = xTxt Then
                MsgBox(i)
            End If
        Next
    End Sub
    
    0 讨论(0)
  • 2020-12-10 13:47

    If you want to select the same item in a listbox using a listview, you can use:

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        For aa As Integer = 0 To ListView1.SelectedItems.Count - 1
            ListBox1.SelectedIndex = ListView1.SelectedIndices(aa)
        Next
    End Sub
    
    0 讨论(0)
  • 2020-12-10 13:54

    ListView returns collections of selected items and indices through the SelectedItems and SelectedIndices properties. Note that these collections are empty, if no item is currently selected (lst.SelectedItems.Count = 0). The first item that is selected is lst.SelectedItems(0). The index of this item in the Items collection is lst.SelectedIndices(0). So basically

    lst.SelectedItems(0)
    

    is the same as

    lst.Items(lst.SelectedIndices(0))
    

    You can also use check boxes. Set CheckBoxes to True for this. Through the CheckedItems and CheckedIndices properties you can see which items are checked.

    0 讨论(0)
  • 2020-12-10 13:55

    Here's the answer that I found for my question:

    urlList1.FocusedItem.Index
    

    And I am getting selected item value by:

    urlList1.Items(urlList1.FocusedItem.Index).SubItems(0).Text
    
    0 讨论(0)
  • 2020-12-10 14:02

    VB6: Listview1.selecteditem

    VB10: Listview1.FocusedItem.Text

    0 讨论(0)
提交回复
热议问题