Fix the current dirty cell when you click the save button from any datagridview document in the form

I have a form with several datagridviews. When saved, the entire dataset will be serialized for the strongly typed property associated with sql varbinary (max) Works fine.

Of course, the current dirty cell will not be saved, as indicated here:

DataGridView -Value is not saved if the selection is not lost from the cell

My problem is that the user can switch from any of the 20 datagridview views when the SAVE button is clicked.

Is there any way if you do not check for the presence of a dirty cell in each datagridview to fix any dirty cell before saving (pressing another control of the text field before saving does the trick, but calls the focus () of this text field before saving not)

I thought that I might have caught the exit event from the grid, but it seems that the main problem is pressing the button (for reasons that I think I understand), does not fire the lost focus events for the current control and seems to no args click handler knows what the currently selected control is.

The guidance is appreciated.

TIA

+3
source share
2 answers

datagridview Leave. . , datagridview, . , , datagrid ...

:

    DataGridView _lastDataGridView = null;
    private void dataGridView_Leave(object sender, EventArgs e)
    {
        _lastDataGridView = sender as DataGridView;
    }

    private void saveButton_Click(object sender, EventArgs e)
    {
        if (_lastDataGridView != null)
        {
            // check if data needs saving...
        }
    }

1: , , . , , DataGridView . DataGridView, , _lastDataGridView sendButton_Click. .

2: datagridview, , . , . "VirtualMode". , . , VirtualMode , DataGridView, . , MSDN.

+1

DataGridView CellEndEdit, , DGV? , SQL, UpdateCommand, SelectCommand DeleteCommand DGV. "" , DataAdapter.Update(myDataSet, "TABLE NAME"); DataAdapter, DataGridView. DGV, .

0

Source: https://habr.com/ru/post/1725645/


All Articles