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

[Solved] StyleSelector Alternatives - Grid Load time is too long

11 Answers 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Timothy
Top achievements
Rank 1
Timothy asked on 02 Dec 2010, 04:58 AM
I have a grid which consists of checkbox columns (About 25 of them). I have a requirement to color the background of the checkbox cells green if and when they are checked. I have this in place and it is working. owever due to the fact that the styleSelector has to be called for everysingle cell the load time is around 25 seconds for the grid.

Without the style selector in place the load time is under 10 seconds. I really need to do all I can to keep the load tim eunder 10 seconds so my question is this. Is there anything else I can do to have greenbackgrounds for checked checkboxes besides using a style selector that will improve load times?


I really need help here as it is preventing from moving forward.

Any alternative approaches would be of great help to me.

Thanks,

Tim

11 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 02 Dec 2010, 08:25 AM
Hello,

 10 seconds for loading is definitely not right with or without style selectors. Can you verify if the grid is not measured with infinity in your case? Except this 25 check box columns do you have any more columns?

All the best,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Timothy
Top achievements
Rank 1
answered on 02 Dec 2010, 08:55 AM
You can see the code that creates the columns here: (In this case there are 25 checkbox columns)
http://www.telerik.com/community/forums/silverlight/gridview/progressbar-frozen-during-column-creation-and-dataload.aspx

Each column has a datatemplate and a styleselector applied to it as you will see in the code.

The data template: (All the data templates are the same aside from the Binding 
<DataTemplate x:Key="Task1CBTemplate">
            <CheckBox IsChecked="{Binding TASK1, Mode=TwoWay}" IsThreeState="True" Click="Checkbox_Click" />
        </DataTemplate>





I am thinking that the style selector is the culprit but who knows. If there is a cleaner method to do what I need to that will improve performance please let me know.


Thanks,
Tim
0
Vlad
Telerik team
answered on 02 Dec 2010, 09:03 AM
Hi,

 Why not create custom column and return desired element with desired style and settings? You can check this blog post for more info about custom columns .

Greetings,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Timothy
Top achievements
Rank 1
answered on 02 Dec 2010, 09:08 AM
I will take a look.

Knowing that I declare the columns in the following manner can you provide an example of how to replace my method with a custom column?

Dim Task2 As String = EventAdmin.Task2.ToString
                    Dim Task2Column As New GridViewColumn()
                    Task2Column.Width = 48
                    Task2Column.UniqueName = "Task2Column"
                    Dim border2 As New Grid()
                    border2.Height = 170
                    border2.Margin = New Thickness(1, 0, -151, 0)
                    Dim textBlock2 As New TextBlock()
                    textBlock2.Text = Task2
                    textBlock2.VerticalAlignment = VerticalAlignment.Bottom
                    textBlock2.HorizontalAlignment = HorizontalAlignment.Left
                    textBlock2.FontSize = 11
                    textBlock2.FontWeight = FontWeights.Normal
                    textBlock2.TextAlignment = TextAlignment.Center
                    textBlock2.UseLayoutRounding = True
                    textBlock2.TextTrimming = TextTrimming.None
                    textBlock2.Margin = New Thickness(9, 0, 0, 0)
                    Dim transform2 As New RotateTransform()
                    transform2.Angle = 270
                    textBlock2.RenderTransform = transform2
                    border2.Children.Add(textBlock2)
                    Task2Column.Header = border2
                    Task2Column.IsSortable = False
                    Task2Column.IsResizable = False
                    Task2Column.IsFilterable = False
                    Task2Column.IsGroupable = False
                    Task2Column.CellTemplate = TryCast(Me.Resources("Task2CBTemplate"), DataTemplate)
                    Dim selector As New ConditionalStyleSelector()
                    selector.ColumnToCheck = ConditionalStyleSelector.CellColumn.TASK2
                    selector.EventToCheck = SelectorEvent
                    Task2Column.CellStyleSelector = selector
                    Me.CheckListItemssDataGrid.Columns.Add(Task2Column)
0
Timothy
Top achievements
Rank 1
answered on 02 Dec 2010, 09:14 AM
Also, If I create a custom column how does that help me with my style selector. Dont I still have to apply it to the custom column?

Please assist.

I need help determining what the best approach to gain the most performance.
  • Revamp the style selector?
  • Custom Column with Style Selector?
  • etc...
0
Vlad
Telerik team
answered on 02 Dec 2010, 09:34 AM
Hello,

 You do not need style selectors with custom columns since you have the data item in CreateCellElement. You can return and style conditionally any UI element in this method. 

Greetings,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Timothy
Top achievements
Rank 1
answered on 02 Dec 2010, 09:53 AM
Okay, I created the custom column but the checked cells are not green on initial load. They only turn green of I scroll into them.

This is how the class looks, what can I change to ensure they are green if needed on initial grid load,

Imports System
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports System.Windows.Ink
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Shapes
Imports Telerik.Windows.Controls
Imports Telerik.Windows.Controls.GridView
  
  
Public Class CustomColumn
    Inherits GridViewDataColumn
    Public Overrides Function CreateCellElement(ByVal cell As GridViewCell, ByVal dataItem As Object) As FrameworkElement
        Dim cb = TryCast(cell.Content, CheckBox)
  
        If cb Is Nothing Then
            cb = New CheckBox()
            cb.Height = 20
            cb.SetBinding(CheckBox.IsCheckedProperty, Me.DataMemberBinding)
            cell.Content = cb
        End If
  
        If cb.IsChecked = "True" Then
            cell.Background = New SolidColorBrush(Colors.Green)
        Else
        End If
        Return cb
    End Function
  
End Class
0
Vlad
Telerik team
answered on 02 Dec 2010, 09:56 AM
Hello,

 I believe that IsChecked is boolean not string.

Regards,
Vlad
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Timothy
Top achievements
Rank 1
answered on 02 Dec 2010, 09:58 AM
Scrolling up and down on the grid applies sporadic background styling as you can see in the attached screenshot. Thoughts?

Thank you very much for all your help.

Tim
0
Timothy
Top achievements
Rank 1
answered on 02 Dec 2010, 10:06 AM
I changed the code as below, but I still have to scroll to see the green background and even then the green background is applied incorrectly and sporadically as in the picture I attached.

If cb.IsChecked = True Then
            cell.Background = New SolidColorBrush(Colors.Green)
0
Timothy
Top achievements
Rank 1
answered on 02 Dec 2010, 10:30 AM
Turning off Row and Column Virtualization resolved the problem. My grid now loads in 3 seconds.

I cant tell you how greatfull I am for your assitance. This is a really big deal for my application and you just saved the day in a very big way.

Thank you, Thank you, Thank you.


You guys should really put the use of custom columns into the documentation and maybe even a video as I know from these forums that alot of people would benefit from this knowledge.

Your silverlight product already rocked and now that I have overcome this performance hit the sky is the limit.

On another note, I am conitnually amazed at the quality of support Telerik has on these forums. You guys are Rock Stars.!!


Tim
Tags
GridView
Asked by
Timothy
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Timothy
Top achievements
Rank 1
Share this question
or