I have a DataGridView. I have to compare the old and the new cell values and perform further action.
I tried comparing with Cell Leave
, CellValidating
events by using the following code,
private void TestGrid_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
int currentCell = TestGrid.CurrentCell.ColumnIndex;
var oldCellValue = TestGrid[e.ColumnIndex, e.RowIndex].Value;
var newValue = e.FormattedValue;
}
It returns my Old value and new value both as eg: 1000 when I try clicking on the different cell.
Please, let me know if there is any other event through which I can achieve the desired behaviour. Also If I have to compare the old and new cells row or column indexes then how to proceed?
private void TestGrid_CellLeave(object sender, DataGridViewCellEventArgs e)
{
int currentCell = TestGrid.CurrentCell.ColumnIndex;
int oldCell = e.ColumnIndex;
}
Both them returns same index.