Вы не можете реализовать событие нажатия кнопки для ячеек кнопки в DataGridViewButtonColumn
.Вместо этого вы используете событие CellClicked
DataGridView и определяете, сработало ли событие для ячейки в вашем DataGridViewButtonColumn
.Используйте свойство события DataGridViewCellEventArgs.RowIndex
, чтобы узнать, какая строка была нажата.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) {
// Ignore clicks that are not in our
if (e.ColumnIndex == dataGridView1.Columns["MyButtonColumn"].Index && e.RowIndex >= 0) {
Console.WriteLine("Button on row {0} clicked", e.RowIndex);
}
}
Документация MSDN для класса DataGridViewButtonColumn содержит более полный пример.