Here's a revision to your code. Changed variable names to be meaningful. Replace the throw with your exception handler.
void education_DGV_CellLeave (
object sender,
DataGridViewCellEventArgs e )
{
if ( e.ColumnIndex < 0 )
{
}
else if ( String.IsNullOrEmpty (
education_DGV.
Columns [ e.ColumnIndex ].HeaderText ) )
{
}
else if ( !( education_DGV.
Columns [ e.ColumnIndex ].HeaderText.
ToLower ( ).
Trim ( ) ).
Equals ( "total marks" ) )
{
}
else if ( e.RowIndex < 0 )
{
}
else
{
string cell_string = String.Empty;
decimal cell_value = -1.0M;
cell_string = education_DGV [ e.RowIndex,
e.ColumnIndex ].
Value.
ToString ( );
if ( String.IsNullOrEmpty ( cell_string ) )
{
}
else if ( !decimal.TryParse ( cell_string,
out cell_value ) )
{
DataGridViewDataErrorEventArgs exception;
exception = new DataGridViewDataErrorEventArgs (
null,
e.ColumnIndex,
e.RowIndex,
DataGridViewDataErrorContexts.
InitialValueRestoration );
education_DGV.CancelEdit ( );
throw new DataException (
String.Format (
"Data error (column {0}, row {1})",
e.ColumnIndex,
e.RowIndex ) );
}
}
}
Hope that helps.