Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right-click to select a datagridview row

How do you select a datagridview row on a right-click?

like image 586
Jeffrey A. Reyes Avatar asked Oct 06 '08 05:10

Jeffrey A. Reyes


2 Answers

from @Alan Christensen code convert to VB.NET

Private Sub dgvCustomers_CellMouseDown(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvCustomers.CellMouseDown
    If e.Button = MouseButtons.Right Then
        dgvCustomers.CurrentCell = dgvCustomers(e.ColumnIndex, e.RowIndex)
    End If
End Sub

I am tested on VS 2017 it working for me!!!

like image 138
IT Vlogs Avatar answered Oct 03 '22 23:10

IT Vlogs


If e.Button = MouseButtons.Right Then
            DataGridView1.CurrentCell = DataGridView1(e.ColumnIndex, e.RowIndex)
End If

code works in VS2019 too

like image 44
Deluxe23 Avatar answered Oct 03 '22 23:10

Deluxe23