on a mouse down in a datagridview cell how can I get both the e.columnindex and the mouse button at the same time

Dov_B
Dov_B used Ask the Experts™
on
on a mouse down on a datgridview I need to know 2 things
which cell was mouse downed
which butoon did he mouse down with (right, or left)

I have been trying differnt datagridview events but they do one or the other but not both
when I try combining them it does not work

vb.net 2008 express
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Hi,

you could do this on the MouseDown Event:
Private Sub dgvAudio_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgvAudio.MouseDown
        Dim intRowIndex as Integer = DataGridView1.HitTest(e.X, e.Y).RowIndex
        Dim intColumn as Integer = DataGridView1.HitTest(e.X, e.Y).ColumnIndex
        Dim Button As Windows.Forms.MouseButtons = e.Button
End Sub
 
 
         

Open in new window

Commented:
Sorry, should be like this:

Private Sub DataGridView1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
        Dim intRowIndex as Integer = DataGridView1.HitTest(e.X, e.Y).RowIndex
        Dim intColumn as Integer = DataGridView1.HitTest(e.X, e.Y).ColumnIndex
        Dim Button As Windows.Forms.MouseButtons = e.Button
End Sub

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial