private void dataGridView1_CellLeave(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex > 1) { int cellValue = Convert.ToInt32(((DataGridViewCell)sender).Value); if (cellValue < 20) { ((DataGridViewCell)sender).Value = 21; } } }
I am trying to get the value of the cell from which the event occurred.
An exception is thrown when I try to apply sender to a DataGridViewCell :
Cannot start an object of type 'System.Windows.Forms.DataGridView' for type 'System.Windows.Forms.DataGridViewCell'.
What do you recommend to me?
I need to check if the value is less than 20, and if so, increase it to 21.
source share