Avatar of FCapo
FCapo
 asked on

vb.net mouse click

Hi,

How can I get the mouse to perform a right click instead of a left click when a user clicks the left mouse button in a specific datgridview column?
Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
Wayne Taylor (webtubbs)

8/22/2022 - Mon
Wayne Taylor (webtubbs)

It'll be easier to handle the left click and perform your desired action when a cell in that column has been clicked.

You can do this in the Datagridview's CellMouseClick event and check the ColumnIndex...

Private Sub DataGridView1_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick
        If e.Button = Windows.Forms.MouseButtons.Left And e.ColumnIndex = 4 Then
            'perform your action here
        End If
End Sub

Open in new window

FCapo

ASKER
Hi,

the problem I'm having is when a user right clicks on a new row in the datagridview under a specific column, I set it to open up a form with various text strings, the user then chooses the string he wants by double clicking it, the form then closes and places the string he selected in the datagridview CELL that was last selected.

This works great on existing rows in the datagridview, but if they right click on a new row, the cell doesn't actually get selected, so when they choose the string, it will place it in the previous row's cell, just like is shown in the attached imagePic
ASKER CERTIFIED SOLUTION
Wayne Taylor (webtubbs)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Your help has saved me hundreds of hours of internet surfing.
fblack61