DataGridView-单击和双击事件未触发 [英] DataGridView - Click and Double click event not firing

查看:190
本文介绍了DataGridView-单击和双击事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个带有datagridview的表单-问题是我无法触发单元格内容doubleclick事件(或click).

我在同一项目中有其他表格,在这些表格中我做过相同的事情,并且它们可以正常工作,但是由于某种原因,该表格无法正常工作.我已经删除了该控件,然后重新添加了它,并删除了所有格式代码,以使代码尽可能简单

有人有什么建议吗?

在双击事件中,我具有以下内容:

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:

Private Sub dgvToDo_CellContentDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
  MsgBox("Hello world")
End Sub



我为设置数据源所做的一切如下所示:

dgv.DataSource = mObjToDoData.GetToDoDataDataset.Tables(0)
这将返回两行数据并完美显示.

任何建议将不胜感激

蚂蚁
新西兰



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

推荐答案

Ants,

当DataGridView设置为ReadOnly模式= false时,将触发CellContentDoubleClick.

请尝试设置
Ants,

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

Please try to set
dgv.ReadOnly = false;



问候,



Regards,


哦,伙计! 句柄"部分在哪里.

尝试添加Handles dgvToDo.CellContentDoubleClick或使用AddHandler


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


当您还将DoDragDrop语句也放置在datagridview的MouseDown事件处理程序中时,CellContentDoubleClick不会触发.
这是我拥有的代码,该代码导致CellContentDoubleClick不触发(原因在此处以黑体字强调):

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



此行引起了问题(至少在我的情况下):
DoDragDrop(gridd.Rows(SourceRowIndex).Cells(SourceColIndex).Value,DragDropEffects.Copy)



This line is causing the problem (at least in my case):
DoDragDrop(gridd.Rows(SourceRowIndex).Cells(SourceColIndex).Value, DragDropEffects.Copy)


这篇关于DataGridView-单击和双击事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆