Check/Uncheck a checkbox on datagridview

前端 未结 16 743
野性不改
野性不改 2020-11-30 11:19

Can someone help me why it doesn\'t work? I have a checkbox and if I click on it, this should uncheck all the checkbox inside the datagridview which were check

16条回答
  •  感情败类
    2020-11-30 11:51

    // here is a simple way to do so
    
    //irate through the gridview
                foreach (DataGridViewRow row in PifGrid.Rows)
                {
    //store the cell (which is checkbox cell) in an object
                    DataGridViewCheckBoxCell oCell = row.Cells["Check"] as DataGridViewCheckBoxCell;
    
    //check if the checkbox is checked or not
                    bool bChecked = (null != oCell && null != oCell.Value && true == (bool)oCell.Value);
    
    //if its checked then uncheck it other wise check it
                    if (!bChecked)
                    {
                        row.Cells["Check"].Value = true;
    
                    }
                    else
                    {
                        row.Cells["Check"].Value = false;
    
                    }
                }
    

提交回复
热议问题