简体   繁体   English

所选单元格不会更改DataGridView中的值

[英]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: 我敢肯定,这非常简单,但是我找不到方法...我有DataGridViewCheckBoxColumn并且需要更新此列中的所有单元格值,如下所示:

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: DataGridView.RefreshEdit()可用于刷新当前编辑单元格的值:

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

dgvStaffs.RefreshEdit();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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