views:

18

answers:

2

Hello everyone. I want to write a condition for when some cells of DataGridView are null or empty. For example if cells[1] isn't null or empty , a method must be run and ... I wrote it in some way , but some of them didn't work, and one of them work but its not good solution for my problem.As you now ,empty and null are different in DataGridView. Additionally , My DataGridView has not been bound to database. How can i do that in best way? Regards.

A: 

DataGridViewCell object has "Value" method which returns callvalue as object, That value you can convert to string then check this string against null or empty.

string val = this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value as string;
if(string.isNullorEmpty(val) ==false)
{
  // your method run.
}
Arseny
A: 

Cell value is a Object. Empty cell Value is null.

DataTable / DataView uses DbNull.Value when Empty.

Strings with Length = 0 are String.Empty

You need verify three options.

x77