Donate

WPF Custom DataGrid Vertical Scrolling Slow With Thousands Of Records

Hello And Good Evening!

I was tasked by our software architect to investigate an existing project of our company as to why a custom WPF DataGrid's vertical scrolling is slow, lagging or sluggish. This project will collect and show thousands of records that composed mostly hardware and software assets and it's related attributes. The DataGrid control used in the project is a custom class that inherits the DataGrid class with user-defined functions that performs specific tasks.
public class clsCustomDataGrid : DataGrid
{ 
  public clsCustomDataGrid()
  {
	 //More codes here...
  }

  //More codes here...
}
We tried setting the virtualizations through the XAML but no luck. The scrolling is still lagging both using the mouse wheel and vertical scroll bar. After several attempts of researching through the forums and trying out the recommended answer, the solution that fixed the vertical scrolling issue is to set the virtualizations of the column, row, VirtualizingPanel and VirtualizingStackPanel through the constructor of the custom DataGrid class.
public class clsCustomDataGrid : DataGrid
{      
  public clsCustomDataGrid()
  {
	 //More codes here...
	 this.EnableColumnVirtualization = true;
	 this.EnableRowVirtualization = true;
	 ScrollViewer.SetIsDeferredScrollingEnabled(this, true); //optional
	 VirtualizingPanel.SetIsVirtualizing(this, true);
	 VirtualizingPanel.SetVirtualizationMode(this, VirtualizationMode.Standard);
	 VirtualizingStackPanel.SetIsVirtualizing(this, true);
	 VirtualizingStackPanel.SetVirtualizationMode(this, VirtualizationMode.Standard);
  }

  //More codes here...
}
After that, the scrolling improved significantly.
WPF Custom DataGrid Vertical Scrolling Slow With Thousands Of Records

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Pass GUID As Parameter To Action Using ASP.NET MVC ContribGrid