【发布时间】:2015-10-13 05:40:29
【问题描述】:
我有一个名为 dgMember_Grade 的数据网格,它从存储过程中获取数据。
其中一列代表名为vacationStart的日期。
我想根据单元格值对行着色,但它在foreach 行上给我一个错误:
无法将类型“char”转换为“System.Windows.Forms.DataGridViewCell”
我试过代码:
foreach (DataGridViewRow Myrow in dgMember_Grade.Rows)
{
foreach (DataGridViewCell cell in Myrow.Cells[26].Value.ToString()) // error on foreach
{
if (cell != null)
{
DateTime date = DateTime.Now;
DateTime expiredate = DateTime.Parse(Myrow.Cells[26].Value.ToString());
if (expiredate < date)
{
Myrow.DefaultCellStyle.BackColor = Color.Red;
}
else
{
Myrow.DefaultCellStyle.BackColor = Color.Green;
}
}
}
}
【问题讨论】:
标签: c# sql-server winforms cell-formatting