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.
You should use Convert. ToBoolean() to check if dataGridView checkBox is checked.
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With