如何使用行号获取ListView的行值?

时间:2019-01-28 02:31:57

标签: vb.net

我是新来的,也是VB.net新手。
有什么方法可以获取行值并将其显示为使用行号的Label。
例如,如果生成的数字是4,是否有任何代码可以从ListView项的第4行获取值?

 Sub Display_NameList() 
     Me.Name_ListView.Items.Clear()
     CONNECTION.Close()
     CONNECTION.Open()

     Query = "Select * From name_listing Where Raffle_Indicator='1'"
     comm = New MySqlCommand(Query, CONNECTION)
     comm.ExecuteNonQuery()
     Reader = comm.ExecuteReader

     While Reader.Read
         Dim lv As ListViewItem
         lv = Name_ListView.Items.Add(Convert.ToString(Reader("ID") & ""))
         lv.SubItems.Add(Convert.ToString(Reader("Name") & ""))
         lv.SubItems.Add(Convert.ToString(Reader("Office") & ""))
     End While 
End Sub

1 个答案:

答案 0 :(得分:0)

列表框示例

Public Class Form1
    Dim codici As String() = {"cod1", "cod2", "cod3", "cod4", "cod5", "cod6"}
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ListBox1.DataSource = codici
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        If Not (ListBox1.SelectedItem Is Nothing) Then
            Label1.Text = ListBox1.SelectedItem.ToString
        Else
            MessageBox.Show("No selection")
        End If
    End Sub
End Class