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

Issue with CellFormatting Keeping Cell ForeColor

2 Answers 152 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 2
Scott asked on 13 Oct 2010, 04:27 PM
I change the Cell Elements ForeColor To Red if the value is less than Zero.

Private Sub GridPrimerResults_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles GridPrimerResults.CellFormatting
        If CInt(e.CellElement.RowInfo.Cells(1).Value) <= 0 Then
            e.CellElement.NumberOfColors = 1
            e.CellElement.ForeColor = Color.Red
            e.CellElement.DrawFill = True
        End If
    End Sub

It works fine on Load.  When I scroll beyond the text that was Default Black, and scroll back up it now becomes red.  When I click to Export the grid to Excel the Forecolor returns. 

Any ideas on why my color changes when I scroll past the values or how I can prevent it from changing to red?

Attached are screen shots of the rows and how the changed after scrolling.

2 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 13 Oct 2010, 05:00 PM
Hello Scott,

Because of virtualization, the grid reuses cells, so you should always set the DrawFill to False and reset the ForeColor property of the current cell if it does not meet your conditions, like so:
Private Sub GridPrimerResults_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles GridPrimerResults.CellFormatting
        If CInt(e.CellElement.RowInfo.Cells(1).Value) <= 0 Then
            e.CellElement.NumberOfColors = 1
            e.CellElement.ForeColor = Color.Red
            e.CellElement.DrawFill = True
         Else
            e.CellElement.DrawFill = False
            e.CellElement.ResetValue(VisualElement.ForeColorProperty)
        End If
    End Sub

For more information about the CellFormatting event please take a look at this help article.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Scott
Top achievements
Rank 2
answered on 13 Oct 2010, 06:42 PM
Thank-you that was very helpful.
Tags
GridView
Asked by
Scott
Top achievements
Rank 2
Answers by
Emanuel Varga
Top achievements
Rank 1
Scott
Top achievements
Rank 2
Share this question
or