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

Hierarchical Grid - Cell Image Bug

1 Answer 97 Views
GridView
This is a migrated thread and some comments may be shown as answers.
George
Top achievements
Rank 1
George asked on 19 May 2009, 05:35 PM
Hi all,

We have implemented a master-detail hierarchical grid. The cell.image property of certain cells in the master grid, and also in the detail grid, is assigned an image depending on the value of some other cell in the same row. Note that not all master records have a corresponding non empty detail grid. Some do, because there is data to display bebeath them, and some do not because there is not any data to display beneath them. The cellformating event is used to assign the corrresponding images to the current cell as follows:

Private Sub FFAViewGrid_CellFormatting(ByVal sender As System.Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles FFAViewGrid.CellFormatting
        If e.CellElement.ColumnIndex = 3 Then
            Try
                Select Case e.CellElement.RowInfo.Cells(5).Value
                    Case "3"
                        e.CellElement.Image = FFAViewGrid.SmallImageList.Images(FFAViewIcons.UpTick_Green)
                    Case "2"
                        e.CellElement.Image = FFAViewGrid.SmallImageList.Images(FFAViewIcons.Minus_Green)
                    Case "0"
                        e.CellElement.Image = FFAViewGrid.SmallImageList.Images(FFAViewIcons.Minus_Red)
                    Case "1"
                        e.CellElement.Image = FFAViewGrid.SmallImageList.Images(FFAViewIcons.DownTick_Red)
                End Select
            Catch

            End Try
      end if
end sub

Initially the grid is displayed in unexpanded mode as in this picture: view picture  In htis example only the period columns labeled Q3-09 and Q4-09 have a non empty hierarchical child grid and have a value in cell(5) of the row to trigger the image property event. All other master rows have a zero value in cell(5) and hence they should not triger the image property event.

However, when you click to expand the master rows to see the detailed child grid for some reason randomly selected empty master rows are populated with cell images. This phenomenon repeats as many times as you expand and unexpand a master row, populating more random master rows with images when it should not. The picture of the undesired output can be viewed here: view picture and here: view picture

We have extensively tried to debug the cellformating event, only to notice that although the row index number was refering to an empty master row, one that  does not have any value in e.CellElement.RowInfo.Cells(5).Value  to trigger the code to display an image in cell(3), the value reported by the debuger for e.CellElement.RowInfo.Cells(5).Value was from another row and not from the one corresponding to the event.

We can only guess that this is a problem related to the fact that not all master records have a non empty detailed child grid. Do you have any other suggestions why is this behaviour caused and how it can be remedied?

Thank you in advance for your kind cooperation.

Regards,

George



1 Answer, 1 is accepted

Sort by
0
Accepted
Jack
Telerik team
answered on 20 May 2009, 09:41 AM
Hello George,

Thank you for contacting us.

RadGridView reuses its cell elements and only cells that are visible on the screen have corresponding visual elements. When scrolling the grid all visual elements remain on their places only the logical cell elements change. This is made to reduce the memory footprint and to optimize the performance.

You should always reset any changed property to its default value when the condition is not true. I modified your code to address the issue:

Private Sub FFAViewGrid_CellFormatting(ByVal sender As System.ObjectByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles FFAViewGrid.CellFormatting 
        If e.CellElement.ColumnIndex = 3 Then 
            Try 
                Select Case e.CellElement.RowInfo.Cells(5).Value 
                    Case "3" 
                        e.CellElement.Image = FFAViewGrid.SmallImageList.Images(FFAViewIcons.UpTick_Green) 
                    Case "2" 
                        e.CellElement.Image = FFAViewGrid.SmallImageList.Images(FFAViewIcons.Minus_Green) 
                    Case "0" 
                        e.CellElement.Image = FFAViewGrid.SmallImageList.Images(FFAViewIcons.Minus_Red) 
                    Case "1" 
                        e.CellElement.Image = FFAViewGrid.SmallImageList.Images(FFAViewIcons.DownTick_Red) 
                    Case Else 
                        e.CellElement.Image = Nothing 
                End Select 
            Catch 
 
            End Try 
      End if 
End Sub 

I hope this helps. If you have any further questions, don't hesitate to ask.

Best wishes,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
George
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or