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

Background Color spreads to other cells when scrolling

3 Answers 67 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
Gone2TheDogs asked on 18 Mar 2019, 03:59 PM

I've looked at other posts, but I didn't see where I went wrong. 

(review attached screenshot for a better understanding)

In my situation, I add background color to row cells where this is an "A" value in the cell. This stands for an aisle in a warehouse.

If you scroll slowly, then the background color stays within the rows with an "A", but if you scroll too fast, the display shows green in various cells. Also, if I clear the grid and rebuild it with new data, the background color is not reset. The previous rows that were green are still green.

What am I missing?

01.Private Sub dgvMain_CellFormatting(sender As Object, e As CellFormattingEventArgs) Handles dgvMain.CellFormatting
02.    If _LeftOrRightConveyor = "LEFT" And e.CellElement.ColumnIndex = AisleColumnLeft_Idx Then
03.        e.CellElement.BackColor = System.Drawing.Color.LightGreen
04.    ElseIf _LeftOrRightConveyor = "RIGHT" And e.CellElement.ColumnIndex = AisleColumnRight_Idx Then
05.        e.CellElement.BackColor = System.Drawing.Color.LightGreen
06.    End If
07. 
08.    If e.CellElement.Value = "A" Then
09.        e.CellElement.BackColor = System.Drawing.Color.Lime
10.    End If
11.End Sub

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 19 Mar 2019, 05:50 AM
Hi,

The RadGridView control is virtualized and the cell elements are being reused to show different data items. Detailed information on the UI virtualization is available here:
Due to the virtualization, it is required to provide an Else clause in the formatting events so that the styles set on a cell element are reset when this element gets synchronized with a different data item. You can consider resetting the back color similarly as demonstrated here: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formatting-cells.

I hope this will help. Let me know if you need further assistance.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
answered on 19 Mar 2019, 10:23 AM
Right there in the documentation in plain view. I appreciate your bringing it to my attention. 
0
Hristo
Telerik team
answered on 20 Mar 2019, 06:57 AM
Hello Bob,

I am glad that I managed to help. Let me know if you need further assistance.

Regards,
Hristo
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
Answers by
Hristo
Telerik team
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
Share this question
or