CheckBox in DataGridView in C#

DataGridView provide checkbox control “DataGridViewCheckBoxColumn” for selecting particular row value. In this article I tell you how to use DataGridView’s checkbox control in your windows application. Steps are given below.

Step 1: Create one windows application and drag-drop DataGridView control.

Step 2: Rightclick on DataGridView and select “Edit Cloumn…” option.

CheckBox in DataGridView in C#

Step 3: Click on button “Add” and select “DataGridViewCheckBoxColumn” option from type comboBox and give that name with header text as below image.

CheckBox in DataGridView in C#

Step 6: After added “DataGridViewChekBoxCOlumn”, your windows form look as below image.

CheckBox in DataGridView in C#

Step 7: Now bind DataGridView from database. Follow below link for binding database table into DataGridView.

http://www.mindstick.com/Articles/48e0cae0-5baa-41fe-946d-37938a717ddd/?Bind%20Dataset%20to%20DataGridView%20C#

Step 8:  Now check your application. My application screen shot as given below.

CheckBox in DataGridView in C#

  1. int i=0;
    foreach (DataGridViewRow dgvR in dgvshow.Rows)
    {
       DataGridViewCheckBoxCell CbxCell = (DataGridViewCheckBoxCell)dgvR.Cells[0];
        if (Convert.ToBoolean(CbxCell.Value) == true)
       {
           i++;
        }
     }

     MessageBox.Show(i.Tostring());

  1. pls help>>> how to save data from datagridview with checkbox into a new database table.......? thanks for the assistance

  1. I am having trouble in counting the checked items on a datagridview checkbox column on  checkbox check. It doesn't give the expected count. Please help me with this. I wrote the code inside the onCellValueChanged event. . .

Leave Comment