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.