Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a DataGridView with a DataGridViewCheckBoxColumn column, which is databound to a list. The problem is that the databound boolean property for this checkbox is updated not when the check box is checked/unchecked, but after the CellLeave event in other words after the cell looses focus. I want this property to be updated right after the check/uncheck. There's an event CurrentCellDirtyStateChanged which is fired right after check/uncheck happens, so I can use it to update the propery manually. Is there a better way to do this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
504 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can listen for the CurrentCellDirtyStateChanged event and force Commit the change:

void dataGridView1_CurrentCellDirtyStateChanged(object sender,
    EventArgs e)
{
    if (dataGridView1.IsCurrentCellDirty)
    {
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...