在VB datagridview中选择一行 [英] Selecting a row in VB datagridview

查看:117
本文介绍了在VB datagridview中选择一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


当用户在我的网格视图中选择一个单元格时,我想选择整个数据行.或在同一行中找到另一个单元格的值.

例如我将在数据库的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.

推荐答案

U向数据网格添加操作,并且int是selectedrow
这样,您就可以选择该行中的所有单元格.

U add a action to the datagrid and the int is the selectedrow
With that int u can select all the cells within that row.

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中选择一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆