2014-03-30 24 views
0

我在处理DataGridView时遇到错误。我想插入一个单元格内的值时,该单元格是空的,所以我做了一个这样的代码如何处理DataGridView列中的条件?

if (dataGridView1.Rows[RowCount - 1].Cells[1].Value = "") 
{ 
    // my statement 
} 
else 
{ 
    // exception statement 
} 

但我下(dataGridView1.Rows[RowCount - 1].Cells[1].Value = "")面积得到一个错误,我想我有,如果修改条件,但没有任何线索。任何人都可以帮助我吗?

回答

1

=是一个赋值操作符。和==作比较。

你的代码更改为:

if (dataGridView1.Rows[RowCount - 1].Cells[1].Value.ToString() == "") 
{ 
    // my statement 
} 
else 
{ 
    // exception statement 
} 
+0

愤怒的公牛我想,它已经给我一个错误的NullReferenceException是unhanded – Xeroth

+0

@ user3021112:您是否尝试过'的ToString()'如图我的答案? –

+0

是我试过的代码。 – Xeroth