I have a button column on a DataGridView and I am trying to handle a Button.Click event but nothing happens when I click a button. Any help?
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show(e.ColumnIndex.ToString());
if (e.ColumnIndex == 5)
{
MessageBox.Show((e.RowIndex + 1) + " Row " + (e.ColumnIndex + 1) + " Column button clicked ");
}
}
I have tried your sample and it works. Did you really bind the event to your
DataGridView?Please check the
InitializeComponent()Method in your<YourFormName>.Designer.csclass.Did it really has
and you don’t remove the handler at another place in code ?
The DataGridViewButtonColumn MSDN page has this to say: