Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot check box in DataGridViewCheckBoxColumn?

I'm creating a simple DataGridView with a check box column and a text column (more columns will follow, but this is the minimal working example that I'm trying to get working). When I run this code, the checkbox columns appears, but I can't check the boxes.

DataGridViewCheckBoxColumn checkColumn = new DataGridViewCheckBoxColumn();
checkColumn.ThreeState = false;
checkColumn.Width = 20;

MyDataGridView.Columns.Add(checkColumn);
MyDataGridView.Columns.Add(new DataGridViewTextBoxColumn());

Since nothing appears in this case, I thought to add some dummy data.

for (int i = 0; i < 10; i++)
{
    MyDataGridView.Rows.Add(new Object[] { true, "test"});
}

Normally, the DataGridView is populated with data bound from a list of custom objects, like in this question of mine, but I thought it would be better to get this working in a basic way before moving on.

I'm not trying to set the checked state programmatically, but rather let the user select and then use that selection in various other event handlers.

like image 240
Ricardo Altamirano Avatar asked Jun 29 '12 21:06

Ricardo Altamirano


People also ask

How to check DataGridView checkbox column checked or not?

You should use Convert. ToBoolean() to check if dataGridView checkBox is checked.


2 Answers

The code seems to be fine, so I just can tell you to check and ensure that the following DataGridView properties are properly set: ReadOnly set to False and Enabled set to True.

like image 61
Luis Quijada Avatar answered Oct 20 '22 05:10

Luis Quijada


I had the same problem, the solution for me was to change the

"EditMode" from "EditProgramatically" into the default of "EditOnKeystrokeOrF2",

this solved my issue.

All the above suggestions were already implemented.

Kind Regards Heider

like image 34
Heider Sati Avatar answered Oct 20 '22 05:10

Heider Sati