In addition to Sandeep's answer, I would add
e.RowIndex >= 0 && e.ColumnIndex >= 0
inside if.
And
IsNullOrEmpty
only takes a
string
as parameter, but
Cell.Value
property is of type
Object
. So you can't pass it directly to the
IsNullOrEmpty
method.
Try th something like this:
if (MainGridView.Rows.Count > 0 && e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
DataGridViewCell cell = MainGridView.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (cell != null && !String.IsNullOrEmpty(cell.Value as string))
{
}
}