Home > DeveloperSection > Articles > CheckBox in DataGridView in C#

CheckBox in DataGridView in C#


C# C# 
Ratings:
5 Comment(s)
 12421  View(s)
Rate this:

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#


Count checked items in DataGridView in C#

By Manmohan Jha on   3 years ago
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());

Help!!!

By oyekunle oyewusi on   3 years ago
pls help>>> how to save data from datagridview with checkbox into a new database table.......? thanks for the assistance


Count Checked Items on Check

By Michelle Baluran on   one year ago
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. . .

Count Checked Items on Check

By John Smith on   one year ago
Michelle Baluran , feel free to ask question on MindStick Forum Section.

Don't want to miss updates? Please click the below button!

Follow MindStick