Vb.net 如何更改datagridview中特定行的颜色,其中单元格值是每天的第一个时间戳?
我有一个datagridview,里面有一系列按日期和时间排序的报告,大约持续了一年Vb.net 如何更改datagridview中特定行的颜色,其中单元格值是每天的第一个时间戳?,vb.net,Vb.net,我有一个datagridview,里面有一系列按日期和时间排序的报告,大约持续了一年 列表如下所示 2015年1月27日上午10:56:32 2015年1月27日上午11:56:41 2015年1月27日下午12:54:42 2015年1月28日上午8:54:54 2015年1月28日晚上9:02:39 2015年1月29日上午11:02:47 2015年1月29日晚上9:03:00 2015年1月30日晚上9:03:00 如何突出显示或更改每个新的一天系列开始的特定行的颜
列表如下所示
2015年1月27日上午10:56:32
2015年1月27日上午11:56:41
2015年1月27日下午12:54:42
2015年1月28日上午8:54:54
2015年1月28日晚上9:02:39
2015年1月29日上午11:02:47
2015年1月29日晚上9:03:00
2015年1月30日晚上9:03:00
如何突出显示或更改每个新的一天系列开始的特定行的颜色?我的意思是突出显示行 新的一天开始的地方,27号,28号etccc。到目前为止,我正在这样努力
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
但是没有任何进一步的想法。有什么指导吗?我想你不需要计算任何东西。我将更改第一行的颜色,然后循环所有行,并将日期与前一行进行比较。如果那天不同,我会改变行的颜色 像这样的
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
Private Sub myFindRow()
'更改第一行的颜色
对于Me.myDatagridView.Rows.Count-1,行索引为整数=1
Dim curRow As DataGridViewRow=Me.myDatagridView.Rows(i)
Dim prevRow作为DataGridViewRow=Me.myDatagridView.Rows(i-1)
如果CType(curRow.Cells(2).Value,DateTime).Date CType(prevRow.Cells(2).Value).Date则
'更改当前行的颜色
如果结束
下一个
端接头
我会比较.Date
属性,而不是。Day
,因为11月11日和12月11日(假设值之间有一个月的间隔)不会检测到值的变化。@JasonFaulkner好主意,我会进行更改OK明白了,对于我来说是整数=1。myDatagridView.Rows.Count-1。。。对的非常非常有用的脚本,非常感谢