Why is IsNewRow property always returning false?

Edward Karak

I have a DataGridView, called IncTbl. I am looping over it, and I am adding the value of what is in column 4, index i to the yearSalary variable:

for (int i = 0; i < IncTbl.Rows.Count; i++)
{
    if (IncTbl.CurrentRow.IsNewRow) break;
    yearSalary += (decimal)IncTbl[4, i].Value;
}

I do not want to add null, because I will get a NullReferenceException, so I am using IsNewRow property. However, it is returning false even when it is a new row. How can I fix this problem?

jbeldock

You are not the only person who has seen this sort of behavior. It appears the IsNewRow has been reported as buggy in this MSDN post.

Incidentaly break is a bit unusual in this context. You might consider slightly adjusting your loop as follows:

 for (int i = 0; i < IncTbl.Rows.Count; i++)
        {
            if (!IncTbl.CurrentRow.IsNewRow)
              yearSalary += (decimal)IncTbl[4,i].Value;
        }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related