我正在尝试从 vb.net 中的列表视图中获取值,但不断收到以下错误:
“SelectedItem”不是“System.Windows.Forms.ListView”的成员。
我想我需要将 eventargs 更改为其他事件类型,但我正在为此苦苦挣扎。有人可以指出我的错误。谢谢
Sub filllistview()
Try
'creatconn()
cn.Open()
Dim cmd As OleDbCommand = New OleDbCommand("Select * from Customers", cn)
dr = cmd.ExecuteReader()
While dr.Read()
ListView1.Items.Add(dr(0).ToString())
ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(dr(1))
End While
Catch ex As Exception
System.Windows.Forms.MessageBox.Show(ex.Message)
Finally
dr.Close()
cn.Close()
End Try
End Sub
需要在这里抓
Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As EventArgs) Handles ListView1.SelectedIndexChanged
Try
showcontectsinlistview()
str = ListView1.SelectedItem **<--- ERROR**
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub