返回获取vb.net中的datagridview单元格值

时间:2010-03-15 13:20:50

标签: vb.net

我试图在单击单元格时返回datagridview单元格中包含的值。任何人都可以使用vb.net?thanks

告诉我如何做到这一点

2 个答案:

答案 0 :(得分:11)

检查此示例代码。关键是使用事件的DataGridViewCellEventArgs参数来查找被点击的单元格RowIndexColumnIndex

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