[英]Change the row color in DataGridView based on the quantity of a cell value
[英]How can i change color of particular row in datagridview, where a cell value is first timestamp of each day?
我有一个数据网格视图,其中填写了大约一年的日期和时间排序的系列报告
列表如下
27/1/2015 10:56:32 AM
27/1/2015 11:56:41 AM
2015年1月27日下午12:54:42
28/1/2015 8:54:54 AM
28/1/2015 9:02:39 PM
29/1/2015 11:02:47 AM
29/1/2015 9:03:00 PM
30/1/2015 9:03:00 PM
如何突出显示或更改每个新系列开始的特定行的颜色? 我的意思是突出显示行
新的一天开始的地方,27日,28日等。 到目前为止,我正在尝试这样
Private Sub myFindRow()
Dim sTime As DateTime = Me.myDataset.myReportTable.Compute("Max(reporttime)", "")
Dim eTime As DateTime = Me.myDataset.myReportTable.Compute("Min(reporttime)", "")
Dim cTime As DateTime = sTime
For Each Day As DateTime In Enumerable.Range(0, (eTime - sTime).Days).Select(Function(i) sTime.AddDays(i))
changeRowColor()
Next Day
End Sub
Private Sub changeRowColor()
For Each myRow As DataGridViewRow In Me.myDatagridView.Rows
Dim myTime As DateTime
myTime = myRow.Cells(2).Value
Next
End Sub
但没有任何想法继续前进。 任何指导?
我认为你不需要计算任何东西。 我会改变第一行的颜色然后我将循环所有行并将日期与前一行进行比较。 如果这一天不同,那么我会改变行颜色。
像这样的东西
Private Sub myFindRow()
' Change the color of the first row
For rowIndex As Integer = 1 To Me.myDatagridView.Rows.Count-1
Dim curRow As DataGridViewRow = Me.myDatagridView.Rows(i)
Dim prevRow As DataGridViewRow = Me.myDatagridView.Rows(i-1)
If CType(curRow.Cells(2).Value, DateTime).Date <> CType(prevRow.Cells(2).Value).Date Then
' Change the color of row curRow
End If
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.