Reputation: 107
I have a datagridview filled with series of reports ordered in date and time for about an year
List is like below
27/1/2015 10:56:32 AM
27/1/2015 11:56:41 AM
27/1/2015 12:54:42 PM
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
How can I highlight or change color of that particular row, where each new day series begins? i mean highlighting row
where new day begins, 27, 28th etccc. So far i am trying like this
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
but not getting any idea to proceed futher. any guidence?
Upvotes: 1
Views: 747
Reputation: 12748
I don't think you need to compute anything. I would change the color of the first row then I would loop all rows and compare the date with the previous row. If the day are different then I would change the row color.
Something like this
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
Upvotes: 3