Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual C#-将事件处理程序与CellDoubleClick事件关联_C#_Datagridview_Overloading - Fatal编程技术网

Visual C#-将事件处理程序与CellDoubleClick事件关联

Visual C#-将事件处理程序与CellDoubleClick事件关联,c#,datagridview,overloading,C#,Datagridview,Overloading,我在VisualStudio中工作,试图在用户双击DataGridView单元格时从该单元格中获取信息。我基本上设置了CellDoubleClick事件,就像其他任何单击事件一样,但这似乎不起作用 代码: 表格1.cs private void dataGridView1_CellDoubleClick(Object sender, DataGridViewCellEventArgs e) { System.Text.StringBuilder messageBoxCS

我在VisualStudio中工作,试图在用户双击DataGridView单元格时从该单元格中获取信息。我基本上设置了CellDoubleClick事件,就像其他任何单击事件一样,但这似乎不起作用

代码:

表格1.cs

private void dataGridView1_CellDoubleClick(Object sender, DataGridViewCellEventArgs e)
    {

        System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
        messageBoxCS.AppendFormat("{0} = {1}", "ColumnIndex", e.ColumnIndex);
        messageBoxCS.AppendLine();
        messageBoxCS.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex);
        messageBoxCS.AppendLine();
        MessageBox.Show(messageBoxCS.ToString(), "CellDoubleClick Event");
    }
Form1.Designer.cs中的相关代码

this.dataGridView1.CellDoubleClick += new System.EventHandler(this.dataGridView1_CellDoubleClick);
我在Form1.Designer代码中得到一个错误,该代码说,“dataGridView1\u CellDoubleClick‘匹配委托’System.EventHandler’没有重载

如何使双击正常工作?
谢谢。

CellDoubleClick事件是一个
DataGridViewCellEventHandler
,而不是

EventHandler`

您应该使用设计器添加事件句柄,设计器将自动使用正确的委托类型。
不应手动编辑设计器生成的代码

通常,在添加事件处理程序时,不应显式创建委托。
相反,你可以写作

myGrid.CellDoubleClick += MyGrid_CellDoubleClick;

好的,我对Visual Studio不是很在行,我当时正绞尽脑汁试图双击工作。在我阅读了你的评论后,我仔细查看了设计器并找到了“事件”按钮。现在它可以工作了。谢谢。如果你有时间,请像我5岁那样向我解释为什么不能简单地执行+=新事件处理程序(MyGrid_CellDoubleClick);若要处理此事件,我不明白。:@JazzCat:因为该事件被声明为不同的类型。