zoukankan      html  css  js  c++  java
  • DataGridViewCheckBoxColumn的Value值和EditFormatedValue值不一致

    今天要做一个代码修改DataGridViewCheckBoxColumn的Value值然后再遍历获取DataGridview选中项,因为遍历的时候为了能获取跟界面一致的选项,所以判断是否选中使用的是EditFormatedValue,所以出现了一个问题:

    虽然修改了Value值,但是EditFormatedValue没有变过,

    查了很多资料没有提到,最后自己乱蒙对了,就是EditFormatedValue值只能是在DataGridview编辑状态下才能修改,所以在修改DataGridViewCheckBoxColumn的Value值前,调用一次datagridview的BeginEdit(),然后在修改结束后调用CommitEdit()就可以让Value和EditFormatedValue同步了,代码如下:

    //gridList是DataGridView类型
    private void UpdateSelections(List<EntityRequest> requestlist)
            {
                if (gridList.Rows.Count <= 0)
                    return;
                EntityRequest temprqs;
                List<object> delItem = new List<object>();
                gridList.BeginEdit(false);
                foreach (DataGridViewRow item in gridList.Rows)
                {
                    temprqs = item.DataBoundItem as EntityRequest;
                    DataGridViewCheckBoxCell checkBoxCell = item.Cells["CheckColumn"] as DataGridViewCheckBoxCell;
                    if (!requestlist.Exists(rqs => rqs.rqs_no == temprqs.rqs_no))
                        if (checkBoxCell.Value != null
                            && (bool)checkBoxCell.Value == true)
                        {
                            checkBoxCell.Value = false;
                        }
                }
                gridList.CommitEdit(DataGridViewDataErrorContexts.Commit);
            }
  • 相关阅读:
    LOJ #6008. 「网络流 24 题」餐巾计划
    P2144 [FJOI2007]轮状病毒
    随记
    1010: [HNOI2008]玩具装箱toy(斜率优化)
    HDU 3507 Print Article(斜率优化)
    4819: [Sdoi2017]新生舞会(分数规划)
    POJ 2976 Dropping tests(01分数规划)
    spoj 104 Highways(Matrix-tree定理)
    dp专练
    4152: [AMPPZ2014]The Captain
  • 原文地址:https://www.cnblogs.com/cellphoneyeah/p/6428238.html
Copyright © 2011-2022 走看看