As i see, you are trying to export data from DataGridView to tab-separated file.
1) Define variable, type of: DataGridViewCell
], to use it inside second loop,
2) Value returned by DataGridViewCell.Value
] is the same type, as its source. So, if
is equal to
, then it can't be null
Quote:In database applications, a null object is a valid value for a field. This class differentiates between a null value (a null object) and an uninitialized value (the DBNull.Value instance). For example, a table can have records with uninitialized fields. By default, these uninitialized fields have the DBNull value.
More about: null (C# reference)
], Nullable Types (C#)
] and DBNull Class
Try to replace:
(dataGridView1.Rows[i].Cells[j].Value != null)
DataGridViewCell cell = this.dataGridView1.Rows[i].Cells[j];
if (cell.Value.ToString != DbNull.Value.ToString)
wr.Write(cell.Value.ToString + "\t");
Have a look at below examples:
More you'll find at CP
textbox in the right-top corner of this site.