This is a migrated thread and some comments may be shown as answers.

RadGrid cell forecolor Issue/Bug?

1 Answer 43 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Manuel
Top achievements
Rank 1
Manuel asked on 10 Oct 2017, 07:18 AM

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

 

1 Answer, 1 is accepted

Sort by
0
Manuel
Top achievements
Rank 1
answered on 10 Oct 2017, 07:29 AM

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

Tags
GridView
Asked by
Manuel
Top achievements
Rank 1
Answers by
Manuel
Top achievements
Rank 1
Share this question
or