I have a custom datagridviewcolumn, a custom control hosted in a cell. I want to programmatically exit edit mode and validate the current value in the cell (this value is correct). I have checked below ways but without success:
this.datagridview.currentCell.datagridview.endEdit()
this.EditingControlDataGridView.endEdit()
this.datagridview.endEdit();
also by forcing the current cell to change:
this.datagridview.currentCell = this.datagridview.Rows[rowIndex].Cells[columnIndex]
I need to programmatically force the commit of the pending value in the cell because for example, there are cases that I need to delete a row of datagridview but as cell (in the same row being deleted) is in edit mode, I cannot do it if I do not commit changes for the cell and exit edit mode before.
Also, I have similar strange behaviour when I want to exit edit mode but, in this case, discarding the changes in the cell: depending on the state of my application, sometimes doing this.datagridview.CancelEdit() works and sometimes not.
Using C#, .NET Framework 4.0, WinForms.