Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi
I have a form with a datagridview - The problem is I can't get the Cell content doubleclick events (or click) to fire.

I have other forms in the same project where I have done the same thing and they work fine, but for some reason this form doesnt. I have deleted the control and re added it and stripped out all my formatting code to make the code as simple as possible

Does any one have any suggestions?

In the double click event I have the following:
VB
Private Sub dgvToDo_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
  MsgBox("Hello world")
End Sub


And all I have done to set my datasource is as follows

dgv.DataSource = mObjToDoData.GetToDoDataDataset.Tables(0)
This returns two rows of data and displays perfectly.

Any suggestions would be much appreciated

Ants
New Zealand
Posted
Updated 21-Nov-19 21:30pm
Comments
Ants Hurdley 18-Jan-11 13:48pm    
Found the problem

I was setting the grid to nothing in the wrong place (dgv= nothing)- idiot - thanks for your help

Ants,

CellContentDoubleClick is fired when the DataGridView is set to ReadOnly mode = false.

Please try to set
dgv.ReadOnly = false;


Regards,
 
Share this answer
 
Comments
Abhinav S 18-Jan-11 2:10am    
Good answer.
Ants Hurdley 18-Jan-11 13:01pm    
Thanks - I changed it to false and yet it still doesn't work. I noted that my other one was set to false - So it sounds as though you are on the right track.
jerrykid 19-Jan-11 2:48am    
Oh, thanks for chosing my answer to be an accepted answer :). The Grid is nothing that's will cause to unhandle the CellContentDoubleClick event, too. :)
O man! Where is the "handles" part.

Try adding Handles dgvToDo.CellContentDoubleClick or use AddHandler

i.e.
Private Sub dgvToDo_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvToDo.CellContentDoubleClick

or
AddHandler dgvToDo.CellContentDoubleClick, AddressOf dgvToDo_CellContentDoubleClick
 
Share this answer
 
v2
Comments
Ants Hurdley 18-Jan-11 12:58pm    
Hi I did have handels in my code - for some reason I didn't copy and paste it properly to this post

Private Sub dgv_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellContentClick
MsgBox("Hello World")
End Sub
Ants Hurdley 18-Jan-11 13:03pm    
and also

Private Sub dgv_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellContentDoubleClick
MsgBox("Hello World")
End Sub
CellContentDoubleClick does not fire when you for instance also place a DoDragDrop-statement in a MouseDown eventhandler for the datagridview.

Here is the code I have, that causes CellContentDoubleClick not to fire (the cause is here emphasized in boldface):

Private Sub gridd_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles gridd.MouseDown
       SourceRowIndex = -1
       SourceColIndex = -1
       If e.Button = Windows.Forms.MouseButtons.Left Then
           If gridd.HitTest(e.X, e.Y).Type = DataGridViewHitTestType.Cell Then
               SourceRowIndex = gridd.HitTest(e.X, e.Y).RowIndex
               SourceColIndex = gridd.HitTest(e.X, e.Y).ColumnIndex
               DoDragDrop(gridd.Rows(SourceRowIndex).Cells(SourceColIndex).Value, DragDropEffects.Copy)
           End If
       End If
   End Sub


This line is causing the problem (at least in my case):
DoDragDrop(gridd.Rows(SourceRowIndex).Cells(SourceColIndex).Value, DragDropEffects.Copy)
 
Share this answer
 
v3
I suggest that you should code it in CellDoubleClick instead of CellContentDoubleClick, it works for me
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900