Right-click in DataGridView to Select Cell

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
 
D

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top