如何从按钮调用 Datagridview 单元格双击事件?

Pat*_*ick 2 c# datagridview

我正在尝试从另一个按钮调用 datagridview 单元格事件方法。

DataGridView 单元格双击方法

private void ListDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                ListDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                DataGridViewRow row = this.ListDataGridView.Rows[e.RowIndex];

                comboBox2.Text = row.Cells[1].Value.ToString();

            }
        }
Run Code Online (Sandbox Code Playgroud)

这是我调用此方法的按钮

private void button6_Click(object sender, EventArgs e)
{
  ListDataGridView_CellDoubleClick(sender, e);
}
Run Code Online (Sandbox Code Playgroud)

我收到的错误

错误 3 命名空间“System”中不存在类型或命名空间名称“DataGridViewCellEventHandler”(您是否缺少程序集引用?)C:\VisualC#\Projects\DataGridViewApplication\DataGridViewApplication\List.Designer.cs 340 46 DataGridViewApplication

我做了什么:

我将 EventArgs 更改为 DataGridViewCellEventArgs。

private void button6_Click(object sender, DataGridViewCellEventArgs e)
   {    
     ListDataGridView_CellDoubleClick(sender, e);
   }
Run Code Online (Sandbox Code Playgroud)

现在我收到错误:

this.button6.Click += new System.EventHandler(this.button6_Click);
Run Code Online (Sandbox Code Playgroud)

错误 3 “button6_Click”没有重载匹配委托“System.EventHandler”

C:\VisualC#\Projects\DataGridViewApplication\DataGridViewApplication\List.Designer.cs 340 35 DataGridViewApplication

现在我将按钮事件处理程序代码更改为此

this.button6.Click += new System.DataGridViewCellEventHandler(this.button6_Click);
Run Code Online (Sandbox Code Playgroud)

仍然收到此错误并卡在此处

错误 3 “button6_Click”没有重载匹配委托“System.EventHandler”

在这里找到了一个解决方案: How to call a datagridview event with a click a button?

private void button6_Click(object sender, EventArgs e)
        {
            ListDataGridView_CellDoubleClick(null, null);  
        }
Run Code Online (Sandbox Code Playgroud)

但这对我不起作用,它给了我一个错误。

你调用的对象是空的。

Val*_*deh 5

    private void button6_Click(object sender, EventArgs e)
    {

        ListDataGridView_CellDoubleClick(this.ListDataGridView, new DataGridViewCellEventArgs(this.ListDataGridView.CurrentCell.ColumnIndex,this.ListDataGridView.CurrentRow.Index));

    }
Run Code Online (Sandbox Code Playgroud)