lundi 27 juin 2022

Checkbox column not getting checked in datagridview c#

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

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;
                        
            }
      }



Aucun commentaire:

Enregistrer un commentaire