问题描述
嗨
当用户在我的网格视图中选择一个单元格时,我想选择整个数据行.或在同一行中找到另一个单元格的值.
例如我将在数据库的gridview中显示5个字段.
(注意:这是一个数据网格视图,显示在VB.net的表单上)
__________________________________________________________
名称|姓| ID号|联络电话|性别|
-------------------------------------------------- --------
约翰| Garth | 012251 | 074 551 2102 |男|
当我选择John或其他任何字段时,我想将ID号存储在变量中
(即使选择ID字段也是如此)
非常感谢.
Hi
when a user selects a single cell in my gridview i want to select the entire row of data. Or find the value of another cell in the same row.
for eg. I''ll have 5 fields displaying in a gridview from a database.
(note : this is a datagridview that is displayed on a form in VB.net)
__________________________________________________________
name | Surname |ID number | contact Number| Gender |
----------------------------------------------------------
john| Garth |012251 | 074 551 2102 | Male |
when I select John or any other field I want to store the ID number in a variable
(even when I select the ID field)
Thank you very much.
推荐答案
Private Sub dtg_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dtg.CellContentClick
Dim int As Integer = Me.dtg.CurrentCell.RowIndex
Dim FirstColumnSelectedRecord As String
'U can use a column index or the columnheader
FirstColumnSelectedRecord = Me.dtg.Item(0, int).Value.ToString
这篇关于在VB datagridview中选择一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!