我有一个称为数据网格的数据网格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;
}
}
}
}