简体   繁体   中英

Selected cell doesn't change value in DataGridView

I am sure almost that it's very easy but I can't find how... I have DataGridViewCheckBoxColumn and I need to update all cell values in this column like below:

private void HCStaffSelect_OnCheckBoxClicked(bool isChecked)
{
    foreach (DataGridViewRow row in dgvStaffs.Rows)
    {
        if (!row.IsNewRow)
        {
            row.Cells[cStaffSelect.Index].Value = isChecked;
        }
    }
}

My problem is that focused (selected) cell doesn't change its value. How to change value so cells too?

DataGridView.RefreshEdit() can be used to refresh the value of the curenly editing cell:

for (int r = 0; r < dgvStaffs.RowCount - 1; r++)
     dgvStaffs[cStaffSelect.Index, r].Value = isChecked;

dgvStaffs.RefreshEdit();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM