Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataGridView column of type DataGridViewCheckBoxCell is constantly readonly/disabled

I am using a .NET Windows Forms DataGridView and I need to edit a DataBound column (that binds on a boolean DataTable column). For this I specify the cell template like this:

DataGridViewColumn column = new DataGridViewColumn(new DataGridViewCheckBoxCell());

You see that I need a CheckBox cell template.

The problem I face is that this column is constantly readonly/disabled, as if it would be of TextBox type. It doesn't show a checkbox at all.

Any thoughts on how to work with editable checkbox columns for DataGridView?

Update: For windows forms, please.

Thanks.

like image 429
Vasile Tomoiaga Avatar asked Sep 16 '08 11:09

Vasile Tomoiaga


People also ask

How do I make a datagridview column read-only?

In the DataGridViewcontrol, the column ReadOnlyproperty value determines whether users can edit cells in that column. For information about how to make the control entirely read-only, see How to: Prevent Row Addition and Deletion in the Windows Forms DataGridView Control.

How to disable checkbox column in datagridviewcheckboxcolumn?

DataGridViewCheckBoxColumn does not have property called disabled so by changing the style of the checkbox you can make it look like as if it is disabled. Look at the following code.

Can I edit cells in a column in the datagridview control?

In this article Not all data is meant for editing. In the DataGridViewcontrol, the column ReadOnlyproperty value determines whether users can edit cells in that column. For information about how to make the control entirely read-only, see How to: Prevent Row Addition and Deletion in the Windows Forms DataGridView Control.

What is textbox column in datagridview?

The DataGridViewTextBoxColumn is a general-purpose column type for use with text-based values such as numbers and strings. In editing mode, a TextBox control is displayed in the active cell, enabling users to modify the cell value. Cell values are automatically converted to strings for display.


2 Answers

Well, after more than 4 hours of debugging, I have found that the DataGridView row height was too small for the checkbox to be painted, so it was not displayed at all. I have found this after an accidental row height resizing.

As a solution, you can set the AutoSizeRowsMode to AllCells.

richDataGrid.AutoSizeRowsMode = System.Windows.Forms.DataGridViewAutoSizeRowsMode.AllCells;

like image 89
Vasile Tomoiaga Avatar answered Sep 28 '22 10:09

Vasile Tomoiaga


Instead of trying to create the column in code, click on the tiny arrow in a box at the top right of the DataGridView control, and select "Edit Columns..." from the menu that appears. In the dialog box, click the Add button, then choose the "Databound column" option and pick the boolean column you're binding to.

like image 22
Phillip Wells Avatar answered Sep 28 '22 11:09

Phillip Wells