System.Windows.Forms.DataGridViewCellFormattingEventArgs'不包含带有1个参数的构造函数

时间:2013-12-06 19:15:23

标签: c# winforms datagridview

编译代码时,我不断收到以下错误消息:

Error   1   'System.Windows.Forms.DataGridViewCellFormattingEventArgs' does not contain a constructor that takes 1 arguments

可能导致它的原因 - 到目前为止这是我的代码:

Form1.Designer.cs

this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellFormattingEventArgs(this.dataGridView1_CellClick);

Form1.cs的

 private void dataGridView1_CellClick(object sender, DataGridViewCellFormattingEventArgs e)
        {
            if (this.dataGridView1.Columns[e.ColumnIndex].Name == "DriverNo")
            {
                MessageBox.Show("Hello");
            }
        }

1 个答案:

答案 0 :(得分:2)

从GUI设计器事件创建事件,你得到这个:

Form1.Designer.cs:

this.dataGridView1.CellFormatting += new System.Windows.Forms.DataGridViewCellFormattingEventHandler(this.dataGridView1_CellFormatting);

并以表格形式:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {

    }

以上与您所拥有的不同。我不确定您是否手动编写了问题中的代码或者是什么。

对于CellClick,代码应为:

Form1.Designer.cs:

this.dataGridView1.CellClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);

和形式:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {

        }