尽管检查,从DataGridViewRow传递的null值

时间:2015-01-12 19:35:33

标签: c#-4.0

这段代码的目标是让每个DataGridViewRow将包含数据作为List中的单独元素。问题是还记录了空行。

foreach (DataGridViewRow row in dataGridView1.Rows)
{
    List<int> rowtemp = new List<int>();
    foreach (DataGridViewCell cell in row.Cells)
    {
        if (cell.Value!=null && cell.Value.ToString().Length > 0)//empty cells are passing this check. Why?
        {
            if (Int32.TryParse(cell.Value.ToString(), out v) == true)
                rowtemp.Add(v);
            else
                ErrorLog("Value must be single number in each cell. It is: " + cell.Value.ToString());
        }
    }
    xmlParse(rowtemp);
}

0 个答案:

没有答案