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'

Recommended Answers

All 5 Replies

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";
dataGridView1.Columns.Add(c);

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;
dt.Rows.Add(dr);
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)

you have to assign a repository control, in this case a checkbox.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.