Gridview行颜色根据条件窗口应用程序更改 [英] Gridview row color change based on condition windows application
问题描述
亲爱的,
1,我有考勤数据库,我想在gridview中调用并更改颜色gridview列名称(ClockIn)如果时间超过9:30 ,
第二,如果时间超过9:30则显示在文本框上或Lable(总晚期)1,依此类推等。
请求帮助我是新人。
我试过下面的代码,但是没有工作
DateTime.Parse(e.Row.Cells [5] .Text)> DateTime.Parse(12:00:00 PM)
我尝试过:
DateTime.Parse(e.Row.Cells [5] .Text)> DateTime.Parse(12:00:00 PM)
这样的事情:
< pre lang =c#> private void myDataGridView_CellFormatting( object sender,DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 5 )
{
var mydatetime = DateTime.Parse(myDataGridView.Rows [e.RowIndex] .Cells [e.ColumnIndex] 。值);
如果(mydatetime.Hour > 9 && mydatetime.Minute > 30 )
{
e.CellStyle.BackColor = Color.Yellow;
}
}
}
确保DataGridView中的DateTime字符串格式正确,例如
2008-05-01 7:34:42Z
,您可以省略时间而不是日期部分。
请参阅:< a href =https://msdn.microsoft.com/en-us/library/system.datetime.parse(v=vs.110).aspx> DateTime.Parse Method(System) [ ^ ]
使用时间字段时,它将是:
private void myDataGridView_CellFormatting( object sender,DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 5 )
{
var mytime = myDataGridView.Rows [e.RowIndex] .Cells [eC olumnIndex]。价值;
if (mytime > 09:30)
{
e.CellStyle.BackColor = Color.Yellow;
}
}
}但是你应该先做一些检查,如果它是有效的时间而不是NULL。
我想将文件保存在文件夹而不是数据库中请帮助我..
Dear all,
1st , I have attendance database and i want to call in gridview and change color gridview column Name(ClockIn) if time exceed 9:30,
2nd, If time exceeded 9:30 then show on textbox OR Lable (Total Late) 1 and so on and on.
Pleas help i'm new one.
I have tried below code but its not working
DateTime.Parse(e.Row.Cells[5].Text) > DateTime.Parse("12:00:00 PM ")
What I have tried:
DateTime.Parse(e.Row.Cells[5].Text) > DateTime.Parse("12:00:00 PM ")
Something like this:
private void myDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == 5) { var mydatetime = DateTime.Parse(myDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value); if (mydatetime.Hour > 9 && mydatetime.Minute > 30) { e.CellStyle.BackColor = Color.Yellow; } } }
Make sure the DateTime string in your DataGridView has the correct format, e.g.
"2008-05-01 7:34:42Z"
, you can omit the Time but not the Date part.
See: DateTime.Parse Method (System)[^]
When working with Time fields, it would be:
private void myDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == 5) { var mytime =myDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; if (mytime > "09:30") { e.CellStyle.BackColor = Color.Yellow; } } }But you should do some checking first, if it is a valid Time and not NULL.
I want to save file in folder instead of database Kindly help me..
这篇关于Gridview行颜色根据条件窗口应用程序更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!