C# 如何分离整个DataGridView的CellClick事件的DataGridViewButton列上的CellClick?

C# 如何分离整个DataGridView的CellClick事件的DataGridViewButton列上的CellClick?,c#,.net,winforms,C#,.net,Winforms,我正在用C#和windows窗体编写一个程序,我遇到了一个问题 我有一个DataGridView,其中我在不同的列中显示数据,并添加了一个DataGridView按钮列。问题是我需要在整个DataGridView.CellClick事件的DataGridView按钮列上分离CellClick事件。要继续,我希望在单击datagrid中的按钮时调用与单击其他单元格时不同的函数 提前感谢。从,处理CellClick事件 dataGridView1.CellClick += n

我正在用C#和windows窗体编写一个程序,我遇到了一个问题

我有一个
DataGridView
,其中我在不同的列中显示数据,并添加了一个
DataGridView按钮列。问题是我需要在整个
DataGridView.CellClick
事件的
DataGridView按钮列上分离
CellClick
事件。要继续,我希望在单击datagrid中的按钮时调用与单击其他单元格时不同的函数

提前感谢。

从,处理
CellClick
事件

    dataGridView1.CellClick +=
        new DataGridViewCellEventHandler(dataGridView1_CellClick);
从中检查列号是否符合预期

void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
    // Ignore clicks that are not on button cells.  
    if (e.RowIndex < 0 || e.ColumnIndex !=
        dataGridView1.Columns["Status Request"].Index) return;
    ....
}
void dataGridView1\u CellClick(对象发送方,DataGridViewCellEventArgs e)
{
//忽略不在按钮单元格上的单击。
如果(e.RowIndex<0 | | e.ColumnIndex=
dataGridView1.Columns[“状态请求”].Index)返回;
....
}

显然,用您自己的列名替换“Status Request”,或者只使用索引值。据我所知,没有办法将事件直接附加到按钮,因为它嵌入的按钮不是实际的“按钮”对象,而只是一个GUI技巧,使其看起来像一个,所以您唯一能做的就是检查列索引。

非常感谢Dax Fohl