February 26, 2014 by Nitesh

How to Add Custom Checkbox Column to DataGridView in Windows Forms


In this post we will see how we can add a custom Checkbox column to an existing DataGridView in windows forms. Generally, when you assign a data source to the DataGridView and the data source contains a “bit” column or “bool” column, DataGridView automatically converts it into a Checkbox column. However, at times we need to provide an extra checkbox column to the end-user so that they can select/un-select records using the same. This post will help you add a custom checkbox to your DataGridView.

This post assumes the name of the DataGridView control as gridRecords and LoadGrid() function assigns the data source to the DataGridView.

        private void LoadGrid()
            gridRecords.DataSource = GetDataFromDatabase();
            if(gridRecords.Columns.Count > 0) // Add Checkbox column only when records are present.
        private void AddCheckBoxColumn()
            DataGridViewCheckBoxColumn doWork = new DataGridViewCheckBoxColumn();
            doWork.Name = "Select";
            doWork.HeaderText = "Select";
            doWork.FalseValue = 0;
            doWork.TrueValue = 1;
            gridRecords.Columns.Insert(0, doWork);

In the above code, we 1st set the DataSource of datagridview to the data that has been brought from DB. Before assigning the DataSource, we ensure that we clear the column collection of the DataGridView so that the checkbox column is not added multiple times. Once the DataSource is set, we check for column count and call a function that adds the custom checkbox to the beginning of the DataGridView.

Hope you like this post.

  • Richelle

    Hi Nitesh,
    Thanks for this post. But i have another question.
    Suppose i already created this one, now, I want to select rows thru checking the checkbox created in every row. Then display the row index of what i have been selected. Can you help me with that? I see that the sample code only display the checkbox but cannot be checked.

    Thank you so much.

    • Nitesh Luharuka

      Hi Richelle,
      Make sure your grid’s ReadOnly property is not marked as True. also, you can allow editing this column by setting this column’s ReadOnly property as false.

Support us!

If you like this site please help and make click on any of these buttons!

Powered by WordPress Popup