本文介绍了的Visual C# - 关联事件处理程序CellDoubleClick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio中工作,并试图从一个DataGridView细胞获取信息时,其上的用户双击。我基本上建立了CellDoubleClick事件就像任何其他的Click事件,但似乎并没有工作。

I'm working in visual studio and trying to get information from a DataGridView cell when the user double clicks on it. I basically set up the CellDoubleClick event just like any other Click event but that doesn't seem to work.

代码:

Form1.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相关代码

Pertinent code in Form1.Designer.cs

this.dataGridView1.CellDoubleClick += new System.EventHandler(this.dataGridView1_CellDoubleClick);



我得到一个错误的Form1.Designer代码,说:不超载的dataGridView1_CellDoubleClick比赛代表System.EventHandler'。

I am getting an error in the Form1.Designer code that says, "No overload for 'dataGridView1_CellDoubleClick' matches delegate 'System.EventHandler'.

我怎样才能获得双击才能正常工作?
感谢。

How can I get the double click to work correctly?Thanks.

推荐答案

CellDoubleClick 事件是 DataGridViewCellEventHandler ,而不是
EventHandler`。

The CellDoubleClick event is a DataGridViewCellEventHandler, not an EventHandler`.

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

You should add the event handles using the designer, which will automatically use the correct delegate type.
You should not edit the designer-generated code manually.

在一般情况下,添加事件处理程序时,你不应该明确而是创建委托结果
,你可以写

In general, when adding event handlers, you shouldn't explicitly create the delegate.
Instead, you can write

myGrid.CellDoubleClick += MyGrid_CellDoubleClick;

这篇关于的Visual C# - 关联事件处理程序CellDoubleClick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:06