RadGridView.RowFormatting Bug?

2 posts, 0 answers
  1. Rafael
    Rafael avatar
    12 posts
    Member since:
    Jan 2011

    Posted 03 Dec 2015 Link to this post

    Hi,

    I'm formatting my RadGridView and changing its color based a cell value. It's working fine but if I scroll up or down It becomes to change all rows color.

    Is it a bug, or I'm doing something wrong?

    Here is my code:

     

    Thank you.

    Private Sub grid_RowFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.RowFormattingEventArgs)
        e.RowElement.RowInfo.MinHeight = 24
        If e.RowElement.RowInfo.Cells("Recusa").Value = "S" Then
          e.RowElement.ForeColor = Color.DarkRed
          e.RowElement.BackColor = Color.Coral
        End If
      End Sub

  2. Ralitsa
    Admin
    Ralitsa avatar
    176 posts

    Posted 04 Dec 2015 Link to this post

    Hello Rafael,

    Thank you for contacting us. 

    Cell elements of RadGridView are created only for currently visible cells and are being reused during operations like scrolling, filtering, grouping and so on. In order to prevent applying the formatting to other columns' cell elements (because of the cell reuse) all customizationс should be reset for the rest of the cell elements. Please refer to the code snippet below how to achieve it: 
    Private Sub RadGridView1_RowFormatting(sender As System.Object, e As Telerik.WinControls.UI.RowFormattingEventArgs) Handles RadGridView1.RowFormatting
        e.RowElement.RowInfo.MinHeight = 24
        If e.RowElement.RowInfo.Cells("TextBoxColumn").Value = "S" Then
            e.RowElement.DrawFill = True
            e.RowElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid
            e.RowElement.ForeColor = Color.DarkRed
            e.RowElement.BackColor = Color.Coral
        Else
            e.RowElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local)
            e.RowElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local)
            e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, Telerik.WinControls.ValueResetFlags.Local)
            e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, Telerik.WinControls.ValueResetFlags.Local)
        End If
    End Sub

    You can find useful information how to customize cells and rows on the following articles: Formatting RowsConditional Formatting RowsConditional Formatting CellsFormatting Cells.  

    Hope this will help you. Let me know if you have any other questions.

    Regards,
    Ralitsa
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top