Just before our upcoming Q1 2011 release (next week) I’ve decided to check RadGridView performance compared to standard Silverlight and WPF DataGrid components and to test this I’ve declared a TabControl with two tabs - RadGridView in the first tab and a standard DataGrid in the second. Both grids are bound to collection with 1 million records.

Having a collection with 1 million objects with many properties (for example 1000 properties) will consume a lot of memory and the creation will be insanely slow and that is why I’ve decided to turn off auto-generated columns for both grids and add desired number of columns programmatically:

XAML

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Title="MainWindow">
    <Grid Margin="100">
        <TabControl>
            <TabControl.Items>
                <TabItem Header="Telerik RadGridView">
                    <TabItem.Content>
                        <telerik:RadGridView x:Name="RadGridView1" AutoGenerateColumns="False" 
                                             ColumnWidth="100" IsReadOnly="True" ShowGroupPanel="False" ItemsSource="{Binding}" />
                    </TabItem.Content>
                </TabItem>
                <TabItem Header="WPF DataGrid">
                    <TabItem.Content>
                        <DataGrid x:Name="DataGrid1" EnableColumnVirtualization="True" AutoGenerateColumns="False" 
                                  ColumnWidth="100" IsReadOnly="True" ItemsSource="{Binding}" />
                    </TabItem.Content>
                </TabItem>
            </TabControl.Items>
        </TabControl>
    </Grid>
</Window>

C#

public MainWindow()
{
    InitializeComponent();

    var columnCount = 1000;
    var rowCount = 1000000;
    var converter = new MyConverter();

    for (var i = 0; i < columnCount; i++)
    {
        RadGridView1.Columns.Add(new GridViewDataColumn()
        {
            Header = string.Format("Column {0}", i),
            DataMemberBinding = new Binding("ID")
            {
                Converter = converter,
                ConverterParameter = i,
            },
        });

        DataGrid1.Columns.Add(new DataGridTextColumn()
        {
            Header = string.Format("Column {0}", i),
            Binding = new Binding("ID")
            {
                Converter = converter,
                ConverterParameter = i,
            },
        });
    }

    DataContext = new ObservableCollection<MyObject>(from i in Enumerable.Range(0, rowCount) select new MyObject() { ID = i });
}
 
  

I’ve used a converter to provide run-time cell values for my 1000 columns since MyObject have only one property – ID:

public class MyConverter : IValueConverter
{
    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return string.Format("Cell {0} {1}", value, parameter);
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return value;
    }

    #endregion
}


To test how both grids will handle such scenario (1mil. records with 1000 columns) you can download this application. Try horizontal and vertical scrolling, sorting, etc. The standard DataGrid have almost no styling (very lightweight templates) and because of this it is one of the fastest grids on the market however I was able to sort and scroll with RadGridView faster.

After wrapping up the WPF comparison, I decided to do the same app in Silverlight. As the standard Silverlight DataGrid does not have any column virtualization nothing showed with 1000 columns and I needed to reduce the number of columns to 300. It should be noted that Silverlight DataGrid is also one of the fastest grids on the market. Yet, the initial load was painfully slow compared to RadGridView and RadGridView outperforms it in all operations such as scrolling, sorting, etc. Not convinced about that? Feel free to download the same solution and see for yourself. Don't just take my word for it :)

Enjoy!


About the Author

Vladimir Enchev

is Director of Engineering, Native Mobile UI & Frameworks

Comments