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'

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.

This article has been dead for over six months. Start a new discussion instead.