Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Contextmenu position in vb.net

Tags:

vb.net

i have a datagridview. On right click it shows a contextmenu but it is always in the right upper corner. I want it so that the menu appears on the cell where user right clicks. It could be Cell 1 or two or whatever.

Thanks Furqan

like image 982
Furqan Sehgal Avatar asked Dec 21 '25 05:12

Furqan Sehgal


1 Answers

The easiest way to do this is to handle showing your context menu on your own (not using the context menu property on the grid view) on MouseDown for the data grid. Like this:

Private Sub DataGridView1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
    If e.Button = Windows.Forms.MouseButtons.Right Then
        ContextMenuStrip1.Show(CType(sender, Control), e.Location)
    End If
End Sub
like image 102
Jay Avatar answered Dec 23 '25 05:12

Jay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!