You cannot call
ToString
(or any other method) on a
null
value, and any call to
ToString
(other than the static
Convert.ToString
) method will always return at the very least an empty string: no successful call to
object.ToString
will ever return a null value.
So this code:
if(dataGridView2.Rows[row.Index].Cells[$"{comboBox1.Text + comboBox2.Text}DataGridViewTextBoxColumn"].Value?.ToString() is null)
Will never evaluate to
true
: it may throw a null reference exception though.
As Graeme has said, the best solution is to exclude the null value rows from your database access via the SQL query you load your DataAdapter / DataSet from.