C# – Event for checkbox on gridview


I have a checkbox column on my gridview in a Windows Application. I want an event as soon as somebody clicks on the checkbox.

How do I do this?

Best Solution

New answer, because now I know it's Windows Form

First of all, you need to set the row to be editable in order to the user click in the chekbox, to avoid that you can see when the client click in the CELL of a row.

Lets say that the first Cell is the checkbox:

and the Second some text...

my code for Form1.cs

public partial class Form1 : Form
    public Form1()

    private void Form1_Load(object sender, EventArgs e)
        dgv.DataSource = new testData[] {
            new testData{ CheckBox = true, Name = "One" },
            new testData{ CheckBox = true, Name = "Two" },
            new testData{ CheckBox = false, Name = "Three" },
            new testData{ CheckBox = false, Name = "Four" }            

    private void dgv_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        if (e.ColumnIndex == 0) // It's the Checkbox Column
            DataGridViewRow dgvr = dgv.Rows[e.RowIndex];
            MessageBox.Show(String.Format("Row {0} was cliked ({1})", (e.RowIndex + 1).ToString(), 

public class testData
    public Boolean CheckBox { get; set; }
    public String Name { get; set; }

the design ... just drag a DataGridView component into the window form, named dgv and in the Events, double click the event CellMouseClick