0

I have 3 content items, two DataGrid and a StackPanel that all need to scroll together in a WPF application. Everything works OK with ScrollViewer as long as I only have a small dataset, but when I get to 500 rows with 150 columns, it lags for about 8 seconds before drawing the screen. After reading this: Unreasonable WPF DataGrid Loading Time I disabled the ScrollViewer and it loaded in just 2.5 seconds.

<ScrollViewer CanContentScroll="True"
              HorizontalScrollBarVisibility="Visible"
              VerticalScrollBarVisibility="Visible">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="20" />
            <RowDefinition Height="22" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <DataGrid x:Name="DataGridViewHeader" CellEditEnding="ColumnNameUpdate" Grid.Row="0" HeadersVisibility="None" HorizontalAlignment="Stretch" Margin="0,0,0,0"  VerticalAlignment="Stretch"  ItemsSource="{Binding}" CurrentCellChanged="DataGridCellChange" Grid.Column="0" DataGridCell.Selected="DataGrid_GotFocus" />
            <StackPanel Orientation="Horizontal" VerticalAlignment="Top" Name="ComboBoxPanel"  Grid.Row="1"  Margin="0,0,0,0"  HorizontalAlignment="Left" >

            </StackPanel>

        <DataGrid x:Name="DataGridView"  Grid.Row="2"    HeadersVisibility="None"    HorizontalAlignment="Stretch" Margin="0,0,0,0"  VerticalAlignment="Stretch"  ItemsSource="{Binding}" CurrentCellChanged="DataGridCellChange" Grid.Column="0"/>

    </Grid>
</ScrollViewer>

The trouble is, that the ScrollViewer offers the following layout, which allows me to rename columns at the top, use a dropdown on the second row to select DataType of that column and then shows the data. With 150 columns, they have to all stay lined up, but performance is taking a huge hit.

While I realize that ScrollViewer is an easy solution, is there a better way when taking performance into account?

Layout Preview

Alan
  • 2,046
  • 2
  • 20
  • 43
  • My suggestion would be to use Paging on Datagrid to show minimum of 20 records. Now if user needs to search a particular record, you can provide a text filer above the grid, where the record will displayed instantly. – Sats Nov 15 '18 at 16:41
  • It is a good suggestion, but not ideal. I am building a universal binary database parser https://www.youtube.com/watch?v=OMeghA82kSk and sometimes the records that help you identify the column and datatype are not visible in the first 100 or so records. I have updated my GUI to allow you to use sliders to select how many records to pull, but still would love to fix this performance issue if possible. – Alan Nov 15 '18 at 16:52
  • reasonable solution will be to have only one DataGird instead of all 2 DataGrids+StackPanel inside ScrollViewer. Retemplate DataGrid headers so each of them includes dropdown – ASh Nov 15 '18 at 18:32
  • Thanks ASh, that was what I wanted, but couldn't make headway with that when I tried here: https://stackoverflow.com/questions/53288632/at-runtime-add-x-number-of-comboboxes-with-selecteditem-to-datagrid-wpf/53300725?noredirect=1#comment93527253_53300725, here: https://stackoverflow.com/questions/53272634/add-stackpanel-to-wpf-datagrid-at-runtime, or here: https://stackoverflow.com/questions/53215418/edit-datagridview-headercell-text-at-runtime So I ended up with this method – Alan Nov 15 '18 at 20:41

1 Answers1

1

remove ScrollViewer and add

   VirtualizingStackPanel.IsVirtualizing="True" 
                VirtualizingStackPanel.VirtualizationMode = "recycling"
                EnableColumnVirtualization = "true"
                EnableRowVirtualization = "true"
                  VirtualizingPanel.IsVirtualizingWhenGrouping="True"
                MaxWidth="2560" MaxHeight="1600"
Ghotekar Rahul
  • 322
  • 3
  • 10