vb.net datagritview用法

来源:百度知道 编辑:UC知道 时间:2024/06/15 04:19:34
如何取得datagritview中选定行的第二列的值 急 !!!

Private Sub DataGridView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseMove
If (e.Button = Windows.Forms.MouseButtons.Left) Then '判断是否鼠标左键
Dim myGrid As DataGridView = CType(sender, DataGridView)
Dim hti As System.Windows.Forms.DataGridView.HitTestInfo
hti = myGrid.HitTest(e.X, e.Y)
'如果点击行标题或者单元格
If hti.Type = DataGridViewHitTestType.RowHeader Or hti.Type = DataGridViewHitTestType.Cell Then
Dim row As Integer
'获取单击行的索引号
row = hti.RowIndex
RoomID = myGrid(0, row).Value '记下员工编号
RoomTypeName = myGrid(1, row).Value.ToString '记下员工名字
DataGridView1.ClearSelection()
DataGridView1.Rows(row).Selected = True
End If
ElseIf (e.Button