Question Change CellStyle.ForeColor based on sequence

gchq

Well-known member
Joined
Dec 14, 2007
Messages
168
Programming Experience
10+
Hi there

I am attempting to find a way to establish if the next row in a column value is out of sequence to change the ForeColor value.

Changing a colour based on the cell value can be done with DataGridViewCellFormattingEventArgs but getting the prior value and comparing it to the last value is the problem


If the column rows have the values


1001
1002
1003
1004 <------- Change font colour
1006 <------- Change font colour
1007
1008

Any ideas?

Thanks
 
You have e.RowIndex and can access value of previous row based on that.
 
How? I thought that only gave the current row!

It does, but if the index of the current row is N then it's pretty easy to calculate the index of the previous and next rows, don't you think? They are simply 1 either side.
 
Talk about lead a horse to water! Yesterday was certainly a brain-fart day!

VB.NET:
Private Sub ChequeRegisterFormat(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs)
        If AcctDG1.Columns(e.ColumnIndex).Name = "Check#" Then
            If Not e.RowIndex = 0 Then
                If Not AcctDG1.Rows(e.RowIndex).Cells("Check#").Value = (AcctDG1.Rows(e.RowIndex - 1).Cells("Check#").Value) + 1 Then
                    e.CellStyle.ForeColor = Color.Red
                End If
            End If
        End If
    End Sub

Thanks!
 
Back
Top