Joe
Joe

Reputation: 101

Create an event for a DataGridViewButtonCell in VB.Net

I have a DataGridViewButtonColumn, but I need it to respond when clicked so I can execute code. Can anyone help?

Upvotes: 0

Views: 1061

Answers (1)

Zz Oussama
Zz Oussama

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

Related Questions