DataGridView -Value does not gets saved if selection is not lost from a cell

前端 未结 6 878
暖寄归人
暖寄归人 2020-12-16 03:53

I am using the DataGridView Control for reading and writing an XML file through XML Serialization.

I have an issue as explained below:

  1. I read an XML fi
6条回答
  •  忘掉有多难
    2020-12-16 04:21

    It's because the edited cell value is not committed to the DataSource until it's validated, which happens when the cell lose focus. If you want to commit the modifications immediately, you can handle the CurrentCellDirtyStateChanged event, and call the CommitEdit method in the handler :

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

提交回复
热议问题