在DataGridView中获取Cell Row的值

时间:2016-03-01 10:25:21

标签: c# winforms datagridview

我正在尝试获取两个columns的值,如果一列是blank,它仍然会返回一个值,例如column1blank并且column2不会仍然会返回一个值。 我的代码:

DateTime rowtype = Convert.ToDateTime(row.Cells["CreatedOn"].Value);
  string status= row.Cells["Status"].Value.ToString();
         if (rowtype < DateTime.Now.AddDays(-7) &&  status == "Open")
            {
               row.HeaderCell.Value = ">7";
            }

如果两列包含正确的值,我该如何更改HeaderCell?

1 个答案:

答案 0 :(得分:1)

根据您的评论:

DateTime rowtype = Convert.ToDateTime(row.Cells["CreatedOn"].Value);
string status= row.Cells["Status"].Value.ToString();
DateTime dt = new DateTime(rowtype.Year, rowtype.Month, rowtype.Day);
DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
if (dt == today.AddDays(-7)  &&  status == "Open")
{
    row.HeaderCell.Value = ">7";
}