我试图在单击单元格时返回datagridview单元格中包含的值。任何人都可以使用vb.net?thanks
告诉我如何做到这一点答案 0 :(得分:11)
检查此示例代码。关键是使用事件的DataGridViewCellEventArgs
参数来查找被点击的单元格RowIndex
和ColumnIndex
。
Private Sub DataGridView1_CellClick(ByVal sender As System.Object, _
ByVal e As DataGridViewCellEventArgs) _
Handles DataGridView1.CellClick
MsgBox(DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)
End Sub
答案 1 :(得分:0)
您可以通过按钮进行呼叫
Dim y As String = DataGridView1.CurrentCell.Value
If IsDBNull(y) Then
Else
TextBox1.Text = y
End If