Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have added checkbox column in datagridview and i want that checkboxes checked if one of my column value == 1 otherwise the checkbox should be unchecked i have written following code where content loads in datagridview and that method is called at form load event but checkboxes not showing checked when first time that method is calling when method gets called second time that is working correct


I have assigned data to datagridview using data Source

What I have tried:

DataGridViewCheckBoxColumn chkboxcolumn = new DataGridViewCheckBoxColumn();
chkboxcolumn.HeaderText = "";
chkboxcolumn.Width = 30;
chkboxcolumn.Name = "checkBoxColumn";

if (!dgvCompany.Columns.Contains(chkboxcolumn.Name))
{
dgvCompany.Columns.Insert(0, chkboxcolumn);
}

for (int i = 0; i < dgvCompany.Rows.Count; i++)
{
if (Convert.ToString (dgvCompany.Rows[i].Cells["CompanyLead"].Value) == "1")
{
dgvCompany.Rows[i].Cells["checkBoxColumn"].Value = true;

}
}
Posted
Comments
matblue25 28-Jun-22 16:17pm    
Have you stepped through it in the debugger to make sure the dgvCompany data is loaded the 1st time it's called?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900