我有这样的数据网格视图:如何让价值在一个变量上的DataGridView选定行双击事件
现在,当第一行被双击我想它的所有数据将被保存在变量,像字段name
应该出现在变量名name
和First Name
应该出现在另一个变量名fname
等等。
我一直在尝试使用DataGridView1.CellContentDoubleClick
事件获取值,该属性名为SelectedCells
,但intellisense未向我提供有关如何获取该特定选定行中每列的值的任何信息。
我有这样的数据网格视图:如何让价值在一个变量上的DataGridView选定行双击事件
现在,当第一行被双击我想它的所有数据将被保存在变量,像字段name
应该出现在变量名name
和First Name
应该出现在另一个变量名fname
等等。
我一直在尝试使用DataGridView1.CellContentDoubleClick
事件获取值,该属性名为SelectedCells
,但intellisense未向我提供有关如何获取该特定选定行中每列的值的任何信息。
最后我得到的答案为我工作所以在这里分享吧:
Private Sub DataGridView1_CellContentClick_1(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick
frm_dashboard.lbl_pnum_text.Text = DataGridView1.SelectedRows(0).Cells(0).Value
frm_dashboard.lbl_pname_text.Text = DataGridView1.SelectedRows(0).Cells(2).Value + " " + DataGridView1.SelectedRows(0).Cells(1).Value
frm_dashboard.lbl_paddress_text.Text = DataGridView1.SelectedRows(0).Cells(4).Value
frm_dashboard.Enabled = True
Me.Hide()
End Sub
不客气 – GeorgeK
要从datagridview的直获取数据,你可以做到以下几点:
Dim fName As String = String.Empty
Dim sName As String = String.Empty
Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentDoubleClick
If DataGridView1.SelectedRows.Count <> 0 Then
Dim row As DataGridViewRow = DataGridView1.SelectedRows(0)
fName = row.Cells("fNameColumnName").Value
sName = row.Cells("sNameColumnName").Value
End If
End Sub
这不会然而与多选属性设置为true工作!
什么是DataGridView的数据源?我只问,因为我接近它的方式取决于它的填充方式。 – GeorgeK