RadGrid cell forecolor Issue/Bug?

2 posts, 0 answers
  1. Manuel
    Manuel avatar
    4 posts
    Member since:
    Sep 2011

    Posted 10 Oct 2017 Link to this post

    Hello,

    I have a Radgrid.

    What i want to do is, that when a numeric value is negative it should be in forecolor red. This is not the Problem.

    But when i group the grid by any of the header other values have forecolor red although the value is not negative and its fieldname is not "erfolg"  or "erfolgprozent".

     

    My code is:

     

     If TypeOf e.CellElement.ColumnInfo Is GridViewDataColumn Then
                If DirectCast(e.CellElement.ColumnInfo, GridViewDataColumn).FieldName.ToLower = "erfolg" Or DirectCast(e.CellElement.ColumnInfo, GridViewDataColumn).FieldName.ToLower = "erfolgprozent" Then
                    If IsNumeric(e.CellElement.Value) Then
                        If CDbl(e.CellElement.Value) < 0 Then
                            e.CellElement.ForeColor = System.Drawing.Color.Red
                        Else
                            e.CellElement.ForeColor = System.Drawing.Color.Black
                        End If
                    End If
                End If
            End If

     

  2. Manuel
    Manuel avatar
    4 posts
    Member since:
    Sep 2011

    Posted 10 Oct 2017 in reply to Manuel Link to this post

    Sorry found the solution by myself.

    the code now is:

     

     Private Sub mygrid_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles mygrid.CellFormatting
            e.CellElement.ForeColor = System.Drawing.Color.Black  <- This line is new
            If TypeOf e.CellElement.ColumnInfo Is GridViewDataColumn Then
                If DirectCast(e.CellElement.ColumnInfo, GridViewDataColumn).FieldName.ToLower = "erfolg" Or DirectCast(e.CellElement.ColumnInfo, GridViewDataColumn).FieldName.ToLower = "erfolgprozent" Then
                    If IsNumeric(e.CellElement.Value) Then
                        If CDbl(e.CellElement.Value) < 0 Then
                            e.CellElement.NumberOfColors = 1
                            e.CellElement.ForeColor = System.Drawing.Color.Red
                        Else
                            e.CellElement.ForeColor = System.Drawing.Color.Black
                        End If
                    End If
                End If
            End If
        End Sub

Back to Top