Right-click in DataGridView to Select Cell

  • Thread starter Thread starter DaveS
  • Start date Start date
D

DaveS

Hi! I have created a simple form with a DataGridView and a
ContextMenuStrip. What I would like to happen is that the user
right-clicks on the cell, and the cell gets selected and the context
menu pops up.

Currently, the users must left-click on the cell to select it, then
right-click to get the context menu.

Is there an easy way to do this through the IDE or code?

TIA,

DaveS
 
I came up with the answer after looking at some to the DataGridView
events. The CellMouseDown event can be used to change the current cell.

Private Sub ChangeCurrentCell(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.DataGridViewCellMouseEventArgs)
Handles dgv.CellMouseDown

If e.Button = Windows.Forms.MouseButtons.Right Then
dgv.CurrentCell = dgvQuotes.Item
(e.ColumnIndex, e.RowIndex)
End If
End Sub

DaveS
 
Back
Top