Reputation: 101
I have a DataGridViewButtonColumn, but I need it to respond when clicked so I can execute code. Can anyone help?
Upvotes: 0
Views: 1061
Reputation: 229
If you want to use the datagridviewcellcontentclick event. and execute your logic if the button cell was clicked. the following code snippet should give you some idea.
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
// find out which column was clicked
if (dataGridView1.Columns[e.ColumnIndex] == Column1)
{
//get the value which you want to display
String customer = (String) dataGridView1.Rows[e.RowIndex].Cells[2].Value;
// display on the new form.
Form form2 = new Form();
form2.Text = customer;
form2.ShowDialog();
}
}
Upvotes: 1