private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "shijian")
{
DateTime hjshijian = Convert.ToDateTime(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
if (hjshijian<= DateTime.Now)
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Red;
}
}
}运行后全部变红了,如果改为if (hjshijian.TimeOfDay >= DateTime.Now.TimeOfDay)显示反的正确,什么问题?该怎样做?
{
if (dataGridView1.Columns[e.ColumnIndex].Name == "shijian")
{
DateTime hjshijian = Convert.ToDateTime(dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);
if (hjshijian<= DateTime.Now)
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Red;
}
}
}运行后全部变红了,如果改为if (hjshijian.TimeOfDay >= DateTime.Now.TimeOfDay)显示反的正确,什么问题?该怎样做?
解决方案 »
- 各位帮我想个英文名字! 拜托啦
- AspnetUpload 2.3.0.60416为什么获取名称是 null?
- C#怎么取自己窗口的句柄@
- 求教——未处理的“System.Data.OleDb.OleDbException”类型的异常出现在 system.data.dll 中
- 新手初试API
- 调用API (DsBrowseForContainer)的时候 当多次调用时就出现异常
- C#开发的大型OA系统源码下载
- 关于子报表的问题,十万火急!请各位高手帮忙,有高分奖励
- 求一本介绍用C#实现Winform编程的实例书
- C#如何将灰度的像素矩阵转为bmp图片对象,显示在picturebox
- 关于cookie的问题。。
- <%@ Page%>
{
时间1 < 时间2;
}
用这看看,应该可以
if (hjshijian.CompareTo(xianzaishijian)>0)
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Red;
}
还是大于号正确小于号错误,有鬼了
1 old greater then new
-1 new greater then old
if(hjshijian<DataTime.Now.AddDay(1))
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
}
}
if (hjshijian<= DateTime.Now)
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Red;
}
else
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.ForeColor = Color.Black;
}
可是为什么呢?