Skip to content

DataGrid janky scroll for large data #10444

Open
@giiyms

Description

@giiyms

Description

Hello,

When rendering a datagrid with lots of columns, say 1000 and 100k rows.
The scrolling performance is very janky for at larger window sizes even with row and column virtualization on.

Reproduction Steps

MainWindow.xaml

<Window x:Class="HorzScroll.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:HorzScroll"
        mc:Ignorable="d"
        Title="MainWindow"
        Height="900"
        Width="1600">
    <Grid>
        <DataGrid Name="dataGrid"
                  AutoGenerateColumns="True"
                  EnableRowVirtualization="True"
                  EnableColumnVirtualization="True"
                  FrozenColumnCount="2"
                   />
    </Grid>
</Window>

MainWindow.xaml.cs

using System.Windows;

namespace HorzScroll;
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        LoadData();
    }

    private void LoadData()
    {
        var dataTable = new System.Data.DataTable();

        var nColumns = 1000;
        var nRows = 100000;

        // Add 1000 columns
        for (int i = 0; i < nColumns; i++)
        {
            dataTable.Columns.Add("Column" + i);
        }

        // Add 1000 rows
        for (int i = 0; i < nRows; i++)
        {
            var row = dataTable.NewRow();
            for (int j = 0; j < nColumns; j++)
            {
                row[j] = $"R{i}C{j}";
            }
            dataTable.Rows.Add(row);
        }

        dataGrid.ItemsSource = dataTable.DefaultView;
    }

}

Expected behavior

I would expect the datagrid to have fast scrolling.

Actual behavior

Janky scrolling when using the scrollbars.

Regression?

No response

Known Workarounds

https://github.com/obiben/DynamicGridControl

This is a link to dynamic grid control example that is smooth to any data sizes with no jankiness with horizontal scroll but lacks the functionality of the datagrid.

It uses building a 2-dimensional item cache for fast lookup during scrolling and recycling display data only when necessary. The performance is exceptional at any screen size.

Impact

No response

Configuration

.NET 9
Windows 11
x64
It is not specific to this configuration.

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvestigateRequires further investigation by the WPF team.PerformancePerformance related issuearea-DataGridDatagrid issue/enhancements

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions