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

RadGridView.RowFormatting Bug?

1 Answer 287 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rafael
Top achievements
Rank 1
Rafael asked on 03 Dec 2015, 07:11 PM

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

1 Answer, 1 is accepted

Sort by
0
Ralitsa
Telerik team
answered on 04 Dec 2015, 01:54 PM
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
Jame
Top achievements
Rank 1
commented on 02 Feb 2022, 11:28 AM | edited

I have a similar issue for the following code and I'm unsure how to stop it incorrectly switching between Dark Orange and Dark Green when scrolling: 

private void gridOrders_RowFormatting(object sender, RowFormattingEventArgs e)
        {
            if (e.RowElement.IsSelected)
            {
                if (anyPicked)
                {
                    e.RowElement.BackColor = partuiallyPickedOrShipped ? Color.DarkOrange : Color.DarkGreen;
                }
                else if (anyPicking)
                {
                    e.RowElement.BackColor = Color.Green;
                }
                else
                {
                    e.RowElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
                }
            }
            else
            {
                e.RowElement.ResetValue(LightVisualElement.BackColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            }
        }

Is there a way to stop it from bugging when it scrolls? 

Is there a way to stop the formatting running when you scroll perhaps?

Dess | Tech Support Engineer, Principal
Telerik team
commented on 02 Feb 2022, 01:03 PM

Hi, Jame,

According to the provided code snippet, it wouldn't be easy to determine what is the exact undesired behavior that you are facing. However, I suppose that the wrong color is applied to some of the rows after scrolling when using the RowFormatting event. Instead of checking the RowElement.IsSelected property, feel free to use the data row's selected state. In other words, use the RowElement.RowInfo.IsSelected property. 

In case you are experiencing any further difficulties, I would recommend you to submit a support ticket and provide a sample project demonstrating the problem you are facing. Thus, we would be able to make an adequate analysis of the precise case and provide further assistance. Thank you in advance for your cooperation.

Jame
Top achievements
Rank 1
commented on 02 Feb 2022, 02:20 PM

This is a visual of what is currently going wrong 

the underlying status should be the same as we aren't changing anything on a cell click event or when scrolling. perhaps the formatting event is being called too early - before the status have been set? it's difficult to debug as the formatting even gets called constantly and appears to be correct in debug

 

Dess | Tech Support Engineer, Principal
Telerik team
commented on 04 Feb 2022, 03:07 PM

Hello, Jame,    

The previously provided code snippet uses the anyPicked flag that is not clear how it is managed in your project. That is why I would kindly ask you to give us more details about how this variable is managed. A complete code snippet that would replicate the undesired behavior on my end would be greatly appreciated. A better option is to submit a support ticket from your Telerik account and provide a sample runnable project demonstrating the problem you are facing.

Off topic, note that some of the themes have the style defined at cells level. Hence it would be a better option to handle the CellFormatting event instead of using the RowFormatting event. 

I am looking forward to your reply.
Tags
GridView
Asked by
Rafael
Top achievements
Rank 1
Answers by
Ralitsa
Telerik team
Share this question
or