Question DataGridViewCheckBoxColumn Rows Unchecked by Default?

chairmanPC

Active member
Joined
Apr 19, 2021
Messages
38
Programming Experience
10+
All of the selection rows in a DataGridView are checked, and I'm trying to set them unchecked at startup.

This didn't work for me:
C#:
private void Form1_Load(object sender, EventArgs e)
{
    DataGridViewCheckBoxColumn chkbox = new DataGridViewCheckBoxColumn();
    chkbox.HeaderText = "Select";
    chkbox.Name = "DGVChkBox";
    selectedCriteriaData.Columns.Insert(2, chkbox);
    chkbox.Selected = false;
}
Any suggestion? Thanks.
 
Last edited by a moderator:
The Selected property of the column has absolutely nothing to do with whether the boxes in the cells are checked. I haven't tested but I would have thought that the boxes would be unchecked by default but, assuming they're checked, you need to do what you would for any other cells and set the Value property. In this case, the Value will be true for checked and false for unchecked, so you must set it to false for every cell.
 
Moved to WinForms...
 
I have always tried to avoid this control as I completely hate it and always have but from what I know of it, the DataGridViewCheckBoxCell is where you set the state of the checkbox and not the DataGridViewCheckBoxColumn.
I haven't tested but I would have thought that the boxes would be unchecked by default
Yep, correct, they are meant too. They may even be null.
All of the selection rows in a DataGridView are checked, and I'm trying to set them unchecked at startup.
Take note of : DataGridViewCheckBoxCell.TrueValue Property (System.Windows.Forms)
 
All of the selection rows in a DataGridView are checked, and I'm trying to set them unchecked at startup.

This didn't work for me:
C#:
private void Form1_Load(object sender, EventArgs e)
{
    DataGridViewCheckBoxColumn chkbox = new DataGridViewCheckBoxColumn();
    chkbox.HeaderText = "Select";
    chkbox.Name = "DGVChkBox";
    selectedCriteriaData.Columns.Insert(2, chkbox);
    chkbox.Selected = false;
}
Any suggestion? Thanks.

Try this to set the initial state for each cell in Form1_Load:

C#:
this.dgvParameters.Rows[i].Cells[j].Value = CheckState.Checked;

this.dgvParameters.Rows[i].Cells[j].Value = CheckState.Unchecked;

or this:

C#:
this.dgvParameters.Rows[i].Cells[j].Value = true;

this.dgvParameters.Rows[i].Cells[j].Value = false;
 
Last edited:
I'm not sure what you mean with "selection rows". But whatever they are, they should most probably NOT be selected at startup, unless you have set some property to true in the designer. I would try to find the cause of this, rather than fight the symptoms.
 
Back
Top Bottom