Click here to Skip to main content
13,152,147 members (39,323 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 26 Feb 2014

How to Add Custom Checkbox Column to DataGridView in Windows Forms

, 26 Feb 2014
Rate this:
Please Sign up or sign in to vote.
How to add a custom Checkbox column to an existing 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 first 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.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nitesh Luharuka
Team Leader Director @ Rebin Infotech
India India
An Independent IT Professional and Consultant on MS Technologies like .Net | MVC | Silverlight | Sharepoint | MS Project Server along with open source CMS Systems like DotNetNuke etc.

I am an enthusiastic technocrat who love to debug problems and solve them. I love writing articles on my website in my spare time. Please visit my Website for more details and subscribe to get technology related tips/tricks.

You may also be interested in...

Comments and Discussions

Generalabout size of that checkbox column Pin
Member 1057144522-Aug-14 20:09
memberMember 1057144522-Aug-14 20:09 
GeneralRe: about size of that checkbox column Pin
Nitesh Luharuka22-Aug-14 23:18
memberNitesh Luharuka22-Aug-14 23:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170924.2 | Last Updated 27 Feb 2014
Article Copyright 2014 by Nitesh Luharuka
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid