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

GridView very slow ~ >50 columns/rows

3 Answers 56 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 17 Aug 2012, 04:59 PM
I am dynamically generating a RadGridView of variable columns/rows. Each cell contains a text box with 2 converters. But the performance gets really slow when I have around 50 columns X 50 rows. And out right crashes at around 280 columns x 280 rows. Any suggestions? Thanks in advance.

The purpose of the converters is to display either orange or blue depending if the value is positive or negative. And adjust the opacity of the color based on its value.

Our suspicion is that since I'm declaring the converter for each cell each time, it consumes a lot of memory. Is there another way to do it since I can not really use template as I do not have the binding variable until run time.

Code Snippet below: ID', 'string Column Name', 'double[] Values' 

Itemsource is a collection of class with 'int
<telerik:RadGridView AutoGenerateColumns="False" Name="CorrelationGrid"
                           CanUserFreezeColumns="False" VerticalAlignment="Stretch"
                           RowIndicatorVisibility="Collapsed" ShowGroupPanel="False"
                           ShowColumnHeaders="true" BorderBrush="Transparent"
                           HorizontalAlignment="Left" IsReadOnly="True" EnableColumnVirtualization="True" EnableRowVirtualization="True">
      </telerik:RadGridView>


protected GridViewColumn CreateContinuousStatisticColumn(string colName, string colHeader, Boolean stringFormat, int i)
        {
            StringBuilder CellTemp = new StringBuilder();
            Style cellStyle = CreateCellStyle();
            CellTemp.Append("<DataTemplate ");
            CellTemp.Append("xmlns='http://schemas.microsoft.com/winfx/");
            CellTemp.Append("2006/xaml/presentation' ");
  CellTemp.Append("xmlns:my='clr-namespace:MyProject;assembly=MyProject' ");
            CellTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' >");
            CellTemp.Append("<Grid HorizontalAlignment='Stretch' Margin='0,0,0,0'>");
            CellTemp.Append("<Grid.Resources>");
            CellTemp.Append("<my:PosColorConverter x:Key='GetPosColorConverter'/>");
            CellTemp.Append("<my:NegColorConverter x:Key='GetNegColorConverter'/>");
            CellTemp.Append("</Grid.Resources>");
            if (stringFormat)
            {
                CellTemp.Append("<Border HorizontalAlignment='Stretch' VerticalAlignment='Stretch' Background='#47A4D0' BorderThickness='0' Opacity='{Binding Path=");
                CellTemp.Append("Values[" + i.ToString(CultureInfo.InvariantCulture) + "]");
                CellTemp.Append(", Mode=OneWay, Converter={StaticResource GetPosColorConverter}}'/>");
                CellTemp.Append("<Border HorizontalAlignment='Stretch' VerticalAlignment='Stretch' Background='#FF6A00' BorderThickness='0' Opacity='{Binding Path=");
                CellTemp.Append("Values[" + i.ToString(CultureInfo.InvariantCulture) + "], Mode=OneWay, Converter={StaticResource GetNegColorConverter}}'/>");
 
                CellTemp.Append("<TextBlock Padding='5,2,5,2' Margin='3' VerticalAlignment='Center' HorizontalAlignment='Center' Text='{Binding Path=Values[" + i.ToString(CultureInfo.InvariantCulture) + "]");
                CellTemp.Append(", StringFormat=n3}' />");
            }           
            else
                CellTemp.Append("<TextBlock Padding='5,2,5,2' Margin='3' VerticalAlignment='Center' HorizontalAlignment='Center' Text='{Binding Path=" + colName + "}' />");
 
            CellTemp.Append("</Grid>");
            CellTemp.Append("</DataTemplate>");
 
            return new GridViewColumn()
            {
                IsFilterable = false,
                IsSortable = true,
                Header = colHeader,
                SortMemberPath = stringFormat ? "Values[" + i.ToString(CultureInfo.InvariantCulture) + "]" : colName,
                UniqueName = colName,
                IsReadOnly = true,
                HeaderTextAlignment = TextAlignment.Center,
                CellTemplate = (DataTemplate)XamlReader.Load(CellTemp.ToString()),
                CellStyle = cellStyle,               
            };
        }

The created columns are returned and added.

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 20 Aug 2012, 05:54 AM
Hi,

 What's your grid version? You can check here an example of RadGridView bound to 1 mil records with 1000 columns:
http://demos.telerik.com/silverlight/#GridView/UIVirtualization 

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
pierreluigi88
Top achievements
Rank 1
answered on 20 Aug 2012, 09:45 AM
Hi Brian,

You may have already tried this, but I found that with virtualisation, explicitly setting the width for each column greatly improves scrolling performance.

Also, if you've got any comboboxes in your grid and the scrolling slows down when they appear, give me a shout as I've got a bit of a hack that helps with them.

Regarding the outright crash - if the error relates to indexes, the latest Telerik binaries fix that in part as I had the same thing. If this doesn't help, then try this experiment: slow down the keyboard repeat rate in Windows control panel. If this prevents the crash then you can handle scrolling using a dispatcher which stops Silverlight being bombarded with e.g. right arrow commands. Again, if this might be of use let me know and I'll post some code.

Matt
0
Brian
Top achievements
Rank 1
answered on 20 Aug 2012, 10:35 PM
Hi Vlad, 

I am using this build: RadControls_for_Silverlight4_2011_2_0920_Dev_hotfix.

Regarding the demo, I see that it is only declaring the converter once and assigning it to each new column. But how can I do that with a TextBox that's contained within a cell content?

Thanks in advance.

Matty: regarding the crash, the Silverlight app actually just freezes with memory increasing up to 1 gig, that is when I force shut it down. So I do not see any errors. And I can not explicitly set width since the column names are dynamic.
Tags
GridView
Asked by
Brian
Top achievements
Rank 1
Answers by
Vlad
Telerik team
pierreluigi88
Top achievements
Rank 1
Brian
Top achievements
Rank 1
Share this question
or