Working with Check boxes in Data Grid

We have all seen samples of how to add a combo box in a grid but we have often faced the difficulty of adding a Check box in a grid. Well this document will give you one way of implementing it. It has to be understood that implementing this is no way a tough task if the correct technique is implemented. To start, add the required style forthe data grid by adding the following lines. Lets call this method AttachDGStyle.

void AttachDGStyle(){

DataGridTableStyle GridStyle =

new DataGridTableStyle();

        GridStyle.MappingName = "LoadType";

/// Setting the grid style, header text,width.


new DataGridTextBoxColumn());


// column name in the DB.


        GridStyle.GridColumnStyles[0].Width = 100;

        GridStyle.GridColumnStyles[0].NullText = "";


new DataGridTextBoxColumn());



        GridStyle.GridColumnStyles[1].Width =160;

        GridStyle.GridColumnStyles[1].NullText = "";

        DataGridBoolColumn active =

new DataGridBoolColumn();


active.MappingName = "ACTIVE_SW";


active.Width =80;

        active.NullText = "";

        active.ReadOnly =

false ;

        ((DataGridBoolColumn)active).TrueValue = "1";

        ((DataGridBoolColumn)active).FalseValue = "0";

        ((DataGridBoolColumn)active).NullValue = "0";




new DataColumn("LOAD_CAT_COD", typeof ( string )));   


new DataColumn("LOAD_CAT_DESC", typeof ( string )));   


new DataColumn("active_sw", typeof ( string )));   

        Activity.TableName = "LoadType";

        MaintenanceDG.DataSource = Activity;



As we know the first two columns are normal columns, while the third one displays the check boxes.In the first two cases we have specified the grid column style as of type DataGridTextBoxColumn, While the third one we have specified of the type DataGridBoolColumn(Note this is the important step). Also notice the way we specify whether the check box is checked or unchecked by DataGridBoolColumn.TrueValue, DataGridBoolColumn.FalseValue, Finally we add this style to the grid style.

It is to be understood that the values are going o be stored in the data base in Boolean format. So that is all that is needed with working with Check boxes in the datagrid.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.