如何在数据网格中选择一行 [英] How to select a row in data grid

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

问题描述

大家好

我在选择数据网格中的一行时遇到问题.我在下面的代码中使用当前行索引.但它不起作用.

Hi everyone

I am facing problem in selecting a row in data grid . i am using current row index in following code. but it is not working.

Private Sub dgvEmployeedetails_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvEmployeedetails.CellContentClick
    

Public Event RowCommand As GridViewCommandEventHandler
        Dim i As Integer
        i = dgvEmployeedetails.CurrentRowIndex()
   
        dgvEmployeedetails.Item(.CurrentRowIndex, 0)
       dgvEmployeedetails.Item(.CurrentRowIndex, 1)
End Sub


where dgvEmployeedetails is data grid name. in which i have 2 colums which is number and name. my requirement is i should be able to select  both columns  when i click with mouse pointer in data grid and all data related to it must be retrived  from database in appropiate fields.     kindly help me how to code. to fulfil my above requirement

推荐答案

Dim ContactName As String
ContactName = dgContactList.CurrentRow.Cells(0).Value




其中cells(0)是您想要的列号,请记住0是第一列




where cells(0) is the column number that you want, remembering that 0 is the first column


这篇关于如何在数据网格中选择一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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