C# DataGridView--突出显示包含延迟项的行
我试图突出显示项目超过返回日期的datagridview行 我在datagridview中有一个列名“预订\返回\日期”。文本格式为2015年10月6日 如果当前日期大于“预订\返回\日期”,则该行高亮显示 下面是我从另一篇文章中找到的代码。我做错了什么C# DataGridView--突出显示包含延迟项的行,c#,mysql,if-statement,datagridview,C#,Mysql,If Statement,Datagridview,我试图突出显示项目超过返回日期的datagridview行 我在datagridview中有一个列名“预订\返回\日期”。文本格式为2015年10月6日 如果当前日期大于“预订\返回\日期”,则该行高亮显示 下面是我从另一篇文章中找到的代码。我做错了什么 foreach (DataGridViewRow row in CheckOut_dataGridView.Rows) { var now = DateTime.Now; var expirationDa
foreach (DataGridViewRow row in CheckOut_dataGridView.Rows)
{
var now = DateTime.Now;
var expirationDate = DateTime.Parse(row.Cells["Reservation_Return_Date"].Value.ToString());
if (now > expirationDate)
{
row.DefaultCellStyle.BackColor = Color.Yellow;
}
}
而是使用CellFormatting事件来更改背景色
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (DateTime.Compare((DateTime)dataGridView1.Rows[e.Index].Cells["Reservation_Return_Date"],DateTime.Now)>0)
e.CellStyle.BackColor = Color.Yellow;
}
在日期比较中可能是“0”是否检查了expirationDate值?