在 vb.net 中返回获取 datagridview 单元格值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2447358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
return get datagridview cell value in vb.net
提问by Selom
Im trying to return the value contained in a datagridview cell upon clicking on the cell. can anyone please show me how to do this using vb.net?thanks
我试图在单击单元格时返回包含在 datagridview 单元格中的值。谁能告诉我如何使用 vb.net 做到这一点?谢谢
回答by M.A. Hanin
Check this sample code. The key is to use the event's DataGridViewCellEventArgs
parameter to find the clicked cell's RowIndex
and ColumnIndex
.
检查此示例代码。关键是使用事件的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
回答by blackofuil
You can call from a button
您可以通过按钮调用
Dim y As String = DataGridView1.CurrentCell.Value
If IsDBNull(y) Then
Else
TextBox1.Text = y
End If