DataGridView CheckBox Not Updating After Programmatic Change in DataTable Bound as DataSource Until Mouseover RRS feed

  • Question

  • I have a DataGridView whose DataSource is assigned a DataTable that contains 2 bool (CheckBox) columns among other column types.  On certain occasions, when the user clicks CheckBox 1 to change its value, I want to set CheckBox 2 to its opposite value.  CheckBox 1's visible check state changes immediately, but CheckBox 2's visible check state doesn't change until I run the mouse over it.

    In my CellContentClick event handler, I invoke dgv.CommitEdit(DataGridViewDataErrorContexts.Commit) to trigger the CellValueChanged event handler where I change CeckBox 2's value in the DataTable.  The value does change, but CheckBox 2 doesn't refresh until I mouse over it. 

    I can get around the problem by invoking dgv.Refresh() and reassigning the FirstDisplayedScrollingRowIndex and FirstDisplayedScrollingColumnIndex in the CellValueChanged event handler after assigning CheckBox 2, but that makes the dgv visually flutter if the scrolling indexes aren't zero.  I invoke dgv.SuspendLayout() at the start and dgv.ResumeLayout at the end of the CellValueChanged event handler, so that's not a fix.

    So, how can I get CheckBox 2 to visually change without having to MouseOver?  Thanks.

    Saturday, August 3, 2019 2:32 PM


  • I just stumbled on the solution while trying to address another problem.  I decided not to delete the post in case it is helpful to someone else.

    I needed to AcceptChanges() in the DataTable after assigning CheckBox 2 in the CellValueChanged event handler.  That eliminated the need to invoke dgv.Refresh().  This is an acceptable solution in my case since I don't need to retain any of the change settings in the DataTable.

    • Marked as answer by Cincy Steve Saturday, August 3, 2019 2:49 PM
    • Edited by Cincy Steve Saturday, August 3, 2019 2:51 PM
    Saturday, August 3, 2019 2:49 PM