The DataGridView.CellValidating event lets you cancel changes to the current cell when the new value is not valid. Use the DataGridViewCellValidatingEventArgs.FormattedValue property to determine the current value. To determine the state of the current cell, use the DataGridViewCellValidatingEventArgs.RowIndex and DataGridViewCellValidatingEventArgs.ColumnIndex properties to access the cell through the DataGridView.Rows collection. To cancel the change, set the System.ComponentModel.CancelEventArgs.Cancel property to true.
When this event is canceled in data-bound mode, the new value is not pushed to the underlying data source. When this event is canceled in virtual mode, the DataGridView.CellValuePushed event will not be raised.