To display a DataGridView column as Read Only I use:

DataGridView.Columns[0].ReadOnly = true;

Is it possible to display a column as boolean checkbox type. The data is yes/no but I want them displayed as a checkbox. Something like:

DataGridView.Columns[2].CellType = Boolean;

but that doesnt work..'bool' is a 'type' but is used like a 'variable'

6 Years
Discussion Span
Last Post by jireh

Can't do it your way - the "CellType" property is read only.

If you are setting the columns in the designer, when you add a new column, you can specify the type from the drop-down.

In code, if you are adding the columns by hand, you can do it this way:

DataGridViewCheckBoxColumn c = new DataGridViewCheckBoxColumn();
c.HeaderText = "Column1";

or, you can build a DataTable, and the types in the DataTable will set the appropriate column types in the DataGridView:

DataTable dt = new DataTable();
dt.Columns.Add("Column1", typeof(String)); // First col is a string
dt.Columns.Add("Column2", typeof(Boolean)); // Second col is a boolean

DataRow dr = dt.NewRow();
dr["Column1"] = "Data";
dr["Column2"] = true;
dataGridView1.DataSource = dt;

The grid is displaying an XML file, so the columns are fixed to the XML elements, I was looking for a way to override a column.


<DataGridCheckBoxColumn Binding="{Binding boolPropertie}" Header="Boolean" Width="*"/>

this will display checkboxes for your bool property

<DataGridTextColumn Binding="{Binding boolPropertie1}" Header="Boolean1" Width="*"/>

this will display the Text version of your bool value(true || false)
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.