Xeroth
Xeroth

Reputation: 107

How to handle if condition within DataGridView columns?

I am having getting an error while handling DataGridView. I want to insert a value inside a cell when that cell is empty so I made a code like this

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

But I am getting an error under (dataGridView1.Rows[RowCount - 1].Cells[1].Value = "")area I think I have to revise the if condition but no clue. Can any one help me in this?

Upvotes: 0

Views: 2840

Answers (1)

Raging Bull
Raging Bull

Reputation: 18737

= is an assignment operator. And == for comparison.

Change your code to:

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

Upvotes: 1

Related Questions