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

Grid performance with conditional formatting

5 Answers 224 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dirk LX
Top achievements
Rank 1
Dirk LX asked on 30 Jul 2010, 10:51 AM
Guys,

I am facing significant performance issues while using the conditional formatting objects like below.
If I do not format my grid it shows up really fast - using the conditional formatting it takes minutes to load.

The data amount I am loading is around 44000 records (7.500 in the Master, the rest in the childgrid).

Is there something I can do to optimize the performance? At the moment it is nearly unusable.

Here is the code I am referring to:

Dim c1 As New ConditionalFormattingObject("ReferenceWeek0", ConditionTypes.Equal, _supplyLogicLayer.Mapping(0), "", True)
c1.RowBackColor = Color.FromArgb(79, 129, 189)
c1.CellBackColor = Color.FromArgb(79, 129, 189)
c1.CellForeColor = Color.White
c1.RowForeColor = Color.White
 
Dim c5 As New ConditionalFormattingObject("Adjusted", ConditionTypes.Equal, "Adjusted Net Requirement (User Input)", "", True)
c5.RowBackColor = Color.Orange
c5.CellBackColor = Color.Orange
c5.CellForeColor = Color.Black
 
Dim c6 As New ConditionalFormattingObject("SupplyAdjusted", ConditionTypes.Equal, "Supply Adj. Forecast (User Input)", "", True)
c6.RowBackColor = Color.Yellow
c6.CellBackColor = Color.Yellow
c6.CellForeColor = Color.Black
 
Dim c2 As New ConditionalFormattingObject("KPI1", ConditionTypes.Equal, "GREEN", "", False)
c2.RowBackColor = Color.FromArgb(97, 189, 122)
c2.CellBackColor = Color.FromArgb(97, 189, 122)
c2.CellForeColor = Color.FromArgb(97, 189, 122)
 
Dim c3 As New ConditionalFormattingObject("KPI2", ConditionTypes.Equal, "YELLOW", "", False)
c3.RowBackColor = Color.FromArgb(254, 221, 107)
c3.CellBackColor = Color.FromArgb(254, 221, 107)
c3.CellForeColor = Color.FromArgb(254, 221, 107)
 
Dim c4 As New ConditionalFormattingObject("KPI4", ConditionTypes.Equal, "RED", "", False)
c4.RowBackColor = Color.FromArgb(246, 150, 136)
c4.CellBackColor = Color.FromArgb(246, 150, 136)
c4.CellForeColor = Color.FromArgb(246, 150, 136)
 
grid.MasterGridViewTemplate.Columns("Measure").ConditionalFormattingObjectList.Add(c1)
grid.MasterGridViewTemplate.ChildGridViewTemplates(0).Columns("Measure").ConditionalFormattingObjectList.Add(c1)
grid.MasterGridViewTemplate.Columns("Measure").ConditionalFormattingObjectList.Add(c5)
grid.MasterGridViewTemplate.Columns("Measure").ConditionalFormattingObjectList.Add(c6)
 
 
For Each dc As GridViewDataColumn In grid.MasterGridViewTemplate.Columns
 
    Select Case dc.FieldName
        Case "ZZMIN"
            dc.Width = 70
            dc.TextAlignment = ContentAlignment.MiddleCenter
            dc.ReadOnly = True
        Case "SourcePlant"
            dc.TextAlignment = ContentAlignment.MiddleCenter
            dc.Width = 70
            dc.ReadOnly = True
        Case "Plant"
            dc.Width = 70
            dc.ReadOnly = True
        Case "Measure"
            dc.Width = 210
            dc.ReadOnly = True
        Case "Material"
            dc.TextAlignment = ContentAlignment.MiddleCenter
            dc.Width = 70
            dc.ReadOnly = True
        Case Else
            If IsDate(dc.FieldName) Then
                'Format values
                dc.FormatString = "{0:####,##0}"
                dc.Width = 70
                dc.TextAlignment = ContentAlignment.MiddleRight
                dc.ReadOnly = False
 
                'add conditional formatting for KPIs to each week column
                dc.ConditionalFormattingObjectList.Add(c2)
                dc.ConditionalFormattingObjectList.Add(c3)
                dc.ConditionalFormattingObjectList.Add(c4)
            End If
    End Select
 
Next
 
'Format childgrid
For Each dc As GridViewDataColumn In grid.MasterGridViewTemplate.ChildGridViewTemplates(0).Columns
    Select Case dc.FieldName
        Case "ZZMIN"
            dc.TextAlignment = ContentAlignment.MiddleCenter
            dc.ReadOnly = True
        Case "SourcePlant"
            dc.TextAlignment = ContentAlignment.MiddleCenter
            dc.ReadOnly = True
        Case "Plant"
            dc.TextAlignment = ContentAlignment.MiddleCenter
            dc.ReadOnly = True
        Case "Measure"
            dc.ReadOnly = True
        Case "Material"
            dc.TextAlignment = ContentAlignment.MiddleCenter
            dc.ReadOnly = True
        Case Else
            If IsDate(dc.FieldName) Then
                dc.FormatString = "{0:####,##0}"
                dc.TextAlignment = ContentAlignment.MiddleRight
                dc.ReadOnly = False
 
                'add conditional formatting for KPIs to each week column
                dc.ConditionalFormattingObjectList.Add(c2)
                dc.ConditionalFormattingObjectList.Add(c3)
                dc.ConditionalFormattingObjectList.Add(c4)
            End If
    End Select
 
Next
grid.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.None
grid.MultiSelect = True

5 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 30 Jul 2010, 01:27 PM
Hello Dirk,

If you just want to color the rows or cells of a grid i would suggest you use the CellFormatting event:
Telerik Documentation Formatting Cells or RowFormatting event:Telerik Documentation Formatting Rows.

And an answer from telerik says that:
 "As long as the RadGridView control uses UI virtualization, GridCellElement and GridRowElement should be used only in formatting events. Please refer to this blog post for more information about virtualization and formatting."

Try them and use whichever suits your needs the best.

Best Regards,
Emanuel Varga
0
Dirk LX
Top achievements
Rank 1
answered on 04 Aug 2010, 04:35 PM
Thanks for the recommendation.

I am now using the cellformatting event but I figure this doesn't affect any childgrids, right?
My formatting does work fine on the mastergridviewtemplate but not within the childgrids.

Any thoughts on it?

If e.CellElement.RowIndex <> -1 Then
    If e.CellElement.ColumnIndex >= 6 Then
        Dim row As GridViewRowInfo = e.CellElement.RowInfo
        Dim dataColumn As GridViewDataColumn = e.CellElement.ColumnInfo
 
        If row.Cells(5).Value.ToString.Contains("KPI") Then
 
            Select Case row.Cells(dataColumn.UniqueName).Value.ToString
                Case "GREEN"
                    e.CellElement.BackColor = Color.Green
                    e.CellElement.ForeColor = Color.Green
 
                Case "RED"
                    e.CellElement.BackColor = Color.Red
                    e.CellElement.ForeColor = Color.Red
 
                Case "YELLOW"
                    e.CellElement.BackColor = Color.Yellow
                    e.CellElement.ForeColor = Color.Yellow
 
            End Select
 
            e.CellElement.NumberOfColors = 1
            e.CellElement.DrawFill = True
        Else
            e.CellElement.DrawFill = False
            e.CellElement.ResetValue(VisualElement.ForeColorProperty)
            e.CellElement.ResetValue(VisualElement.BackColorProperty)
        End If
    Else
        e.CellElement.DrawFill = False
        e.CellElement.ResetValue(VisualElement.ForeColorProperty)
        e.CellElement.ResetValue(VisualElement.BackColorProperty)
    End If
Else
 
    e.CellElement.DrawFill = False
    e.CellElement.ResetValue(VisualElement.ForeColorProperty)
    e.CellElement.ResetValue(VisualElement.BackColorProperty)
End If
0
Martin Vasilev
Telerik team
answered on 04 Aug 2010, 05:01 PM
Hello Dirk,

Thank you for writing.

It is possible to experience some performance slowdown when you have a lot of rows and  many condition objects. We are aware of that and we will consider improving the performance in a future release. For the time being I would recommend the same as Emanuel suggested: use the Row/CellFormatting event instead.

Let me know if you have any additional questions.

Best wishes,
Martin Vasilev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Dirk LX
Top achievements
Rank 1
answered on 04 Aug 2010, 05:19 PM
Thanks,

I did it exactly like Emanual recommended.

This workaround works perfectly fine for the mastergridviewtemplate but not for my childgrid.
I figure the event cell/rowformatting is not fired in a childgridtemplate, right?

How can I format my childgridentries cellbased?

Any thoughts?

Thanks,
Lars
0
Dirk LX
Top achievements
Rank 1
answered on 04 Aug 2010, 05:22 PM
Issue solved.

I have been confused.

Thanks
Tags
GridView
Asked by
Dirk LX
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Dirk LX
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or