How about this:
if (dataGridView2.Columns[e.ColumnIndex].Name == "ColumnName")
{
if (String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dataGridView1.Rows[e.RowIndex].ErrorText =
"Column Name must not be empty";
e.Cancel = true;
}
}
Also can use:
foreach (DataGridViewRow rw in this.dataGridView2.Rows)
{
for (int i = 0; i < rw.Cells.Count; i++)
{
if (rw.Cells[i].Value == null || rw.Cells[i].Value == DBNull.Value || String.IsNullOrWhitespace(rw.Cells[i].Value.ToString())
{
}
}
}