03
Jul
08

Select row on DataGridView right click

This was the suggested way to acomplish a row select from a couple sources:

Private Sub dataGrid1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseUp

Dim pt = New Point(e.X, e.Y)

Dim hti As DataGrid.HitTestInfo = DataGridView1.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then

DataGridView1.CurrentCell = New DataGridCell(hti.Row, hti.Column)

DataGridView1.Select(hti.Row)

End If

End Sub

I found a much easier way:

Private Sub DataGridView1_CellMouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseUp

DataGridView1.CurrentCell = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)

DataGridView1.Rows(e.RowIndex).Selected = True

End Sub


0 Responses to “Select row on DataGridView right click”



  1. No Comments Yet

Leave a Reply




 

July 2008
M T W T F S S
« Jun   Aug »
 123456
78910111213
14151617181920
21222324252627
28293031