1

I'm having a problem with my ListView/GridView. In fact, my grid has 285 rows, and 24 columns constructed dynamically.

My grid was so slow then I decided to do some other tests directly in XAML (which theorically should be more efficient). All the columns have a CellTemplate.

You can easily reproduce the issue with this :

<Window x:Class="WpfApplication2.HighColumns"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="HighColumns" Height="300" Width="300">
<Window.Resources>
    <DataTemplate x:Key="myCellTemplateMonth">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Border Grid.Column="0" BorderThickness="1,0,1,1" SnapsToDevicePixels="True" BorderBrush="Black" Margin="-6,0,-6,0">
                <TextBlock Grid.Column="0" Text="{Binding}"/>
            </Border>
            <Border Grid.Column="1" BorderThickness="1,0,1,1" SnapsToDevicePixels="True" BorderBrush="Black" Margin="-6,0,-6,0">
                <TextBlock Grid.Column="0" Text="{Binding}"/>
            </Border>
        </Grid>
    </DataTemplate>
</Window.Resources>
<Grid>
    <ListView Background="Transparent" BorderThickness="0" Name="lv2" Grid.Column="1">
        <ListView.ItemContainerStyle>
            <Style TargetType="{x:Type ListViewItem}">
                <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                <Setter Property="VerticalContentAlignment" Value="Stretch"/>
            </Style>
        </ListView.ItemContainerStyle>
        <ListView.View>
            <GridView x:Name="gv1">
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                    <!--<GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>              
                                <Border Grid.Column="0" BorderThickness="1,0,1,1" SnapsToDevicePixels="True" BorderBrush="Black" Margin="-6,0,-6,0">
                                    <TextBlock Grid.Column="0" Text="{Binding}"/>
                                </Border>
                                <Border Grid.Column="1" BorderThickness="1,0,1,1" SnapsToDevicePixels="True" BorderBrush="Black" Margin="-6,0,-6,0">
                                    <TextBlock Grid.Column="0" Text="{Binding}"/>
                                </Border>
                            </Grid>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>-->
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Indics" CellTemplate="{StaticResource myCellTemplateMonth}">
                </GridViewColumn>
            </GridView>
        </ListView.View>
        <sys:DateTime>1/2/3</sys:DateTime>
        <sys:DateTime>4/5/6</sys:DateTime>
        <sys:DateTime>7/8/9</sys:DateTime>
        <sys:DateTime>10/11/12</sys:DateTime>
        [paste the previous 4 ligns here in order to have around 300 rows]
    </ListView>
</Grid>

You can see a "double column" style in each column (with a little graphic bug, but don't pay attention to this fact).

The main issue here is the SLOW of the grid, it's clearly not usable as a professional grid... I tried to active virtualization, and to disable it (when virtualization is disabled, it takes around 17-18 seconds to load the grid...)

Is there some tricks to achieve a high speed grid or something I'm doing wrong ? I was first using the WPF Toolkit Datagrid (I use WPF 3.5 with Windows XP) and I got the same issue so as I only want display of data (and no edition at all), I got back to the "old fashioned" ListView with GridView inside... with no effect IMHO..

Thanks !

EDIT 1 : It seems that I've reached the maximum of a WPF GridView performance possibility... The example written before is just a "simple" list... Consider that I bind not just string but a dictionary and a complex structure. In addition, All this WPF Application is a Class Library, Launched by a VSTO Add-in.

Conclusion : The gridview is unusable as is... and loads in 22 seconds when I disable the virtualization.

It seems that I'll have to use a WinForm DataGridView into my WPF Window... Do you think the problem could be solved using this ?

metalcam
  • 392
  • 2
  • 16
  • On my PC, VirtualizingStackPanel.IsVirtualizing="True" on ListView makes it to load in 1 second. VirtualizingStackPanel.IsVirtualizing="False" takes 6-8 seconds. BTW why do you want so many rows and columns? What kind of data is it? – publicgk May 12 '11 at 08:32
  • Columns are generated dynamically (one column = one year), and it's a "comparing" table (for each column, there is 2 sub columns - before / after). Rows are something I can't tell you about, but whatever the data is (I tested with some strings), the problem still remains the same. When you tried with VirtualizingStackPanel.IsVirtualizing="True", did you feel that the vertical scrolling where extremely slow ? – metalcam May 12 '11 at 09:17
  • only a slight slow (acceptable) but not extremely. Is your PC quite old one? – publicgk May 12 '11 at 10:46
  • Pentium 4 2.80 Ghz, 3GM RAM, Windows XP SP3. The problem here is that my application will be deployed on computers less powerful than mine, so it will be at least the same, and even worst ! – metalcam May 12 '11 at 10:57
  • I Modified my initial post... – metalcam May 12 '11 at 14:26
  • hmm... I believe you have enough RAM but the processor is bit old (for kind of data that you want to display) and the graphics chipset in your PC might also be relatively old. Don't get me wrong. WPF is good enough to work on PCs like yours, however, if you want to display such a huge amount of data, it might get bit slow on older machines. BTW, why can't you enable virtualization? I believe enabling it would bring it to 1-2 second which might be acceptable. – publicgk May 13 '11 at 07:35

1 Answers1

0

Are you shure that the GridView is the problem? I remember from an elder project that I have visualized huge GridViews (up to 100 columns) without problems.
Try removing the binding from your DataTemplate, and try if it is slow withouth the bindings. If not, the problem lies in the ToString() method of your source-objects.

<DataTemplate x:Key="myCellTemplateMonth">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Border Grid.Column="0" BorderThickness="1,0,1,1" SnapsToDevicePixels="True" BorderBrush="Black" Margin="-6,0,-6,0">
                <TextBlock Grid.Column="0" Text="Test withouth binding"/>
            </Border>
            <Border Grid.Column="1" BorderThickness="1,0,1,1" SnapsToDevicePixels="True" BorderBrush="Black" Margin="-6,0,-6,0">
                <TextBlock Grid.Column="0" Text="Test withouth binding"/>
            </Border>
        </Grid>
    </DataTemplate>
HCL
  • 36,053
  • 27
  • 163
  • 213