Triggering a checkbox value changed event in DataGridView

前端 未结 15 2885
一生所求
一生所求 2020-12-01 08:02

I have a grid view that has a check box column, and I want to trigger a drawing event as soon as the value of the cell is toggled. I tried the ValueChaged and the CellEndEdi

15条回答
  •  春和景丽
    2020-12-01 08:13

    Working with an unbound control (ie I manage the content programmatically), without the EndEdit() it only called the CurrentCellDirtyStateChanged once and then never again; but I found that with the EndEdit() CurrentCellDirtyStateChanged was called twice (the second probably caused by the EndEdit() but I didn't check), so I did the following, which worked best for me:

        bool myGridView_DoCheck = false;
        private void myGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (!myGridView_DoCheck)
            {
                myGridView_DoCheck = true;
                myGridView.EndEdit();
                // do something here
            }
            else
                myGridView_DoCheck = false;
        }
    

提交回复
热议问题