当前位置:编程学习 > C#/ASP.NET >>

vb.net 2008 在鼠标单击DataGridView 某一行时 获取这行的值

补充:我最后这样解决的 】 rows = DataGridView1.CurrentCellAddress.Y.ToString() ' 得到选中行的索引值 ID = CInt(DataGridView1.Rows(rows).Cells(0).Value) Name = CStr(DataGridView1.Rows(rows).Cells(1).Value) Desc = CStr(DataGridView1.Rows(rows).Cells(2).Value) Group = CStr(DataGridView1.Rows(rows).Cells(3).Value) Date = CStr(DataGridView1.Rows(rows).Cells(4).Value) 这样更简单一点 谢谢!
答案:Private Sub DataGridView1_CurrentCellChanged(By Val sender As Object, By Val e As System.EventArgs) Handles DataGridView1.CurrentCellChanged

//获取选中行第一列的值,也就是第0列的值
Dim result1 As String = DataGridView1.Item(0, DataGridView1.CurrentCell.RowIndex).Value.ToString.Trim

//获取选中行第二列的值,也就是第1列的值
Dim result1 As String = DataGridView1.Item(1, DataGridView1.CurrentCell.RowIndex).Value.ToString.Trim

'......有几列就写几列,如果感觉这样写代码比较累赘,你可以放到for循环里面,把列数用一个变量i代替旧可以了

End sub

上一个:帮忙用vb.net写个获取屏幕坐标的小程序
下一个:VB.NET 的winform程序数据库安全问题

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,