Items missing until resize

 I'm having a strange issue where sometimes when clearing and adding a new range of items from the SfDataGrid.ItemsSource, a bunch of blank items get placed in the list instead of the expected content.

They're sometimes all together in a clump, but sometimes they're interspersed with valid items.

When I take a look at the items in the Live Visual Tree in Visual Studio, I can see that for each blank item in the SfDataGrid, there is corresponding a VirtualizingCellsControl that doesn't have any content (ie. no child controls).

But I've found that simply resizing the parent window by a few pixels will actually refresh/create the content for each VirtualizingCellsControl that is missing it.

This doesn't happen every time, but it is fairly reproducible.

Any ideas?



3 Replies

SG Santhosh Govindasamy Syncfusion Team February 28, 2025 03:08 PM UTC

Hi Naim William Kingston,

Thank you for reaching out.

Based on the provided information, we attempted to replicate the reported scenario on our end but were unable to reproduce the issue. It worked as expected. For your reference, we have attached a sample—please review it.


To proceed further, could you please share details on how you cleared and added the new range of items to the grid? Additionally, share the relevant code snippet. If possible, kindly replicate the issue in the provided sample, as it will help us investigate further.

Thank you for your cooperation. We look forward to your response.

Regards,
Santhosh.G


Attachment: SfDataGrid_Demo_e9447e7d.zip


NW Naim William Kingston March 2, 2025 02:40 AM UTC

I've attached a more representative example of how I am adding and removing items from the SfDataGrid, but unfortunately have not been able to reproduce the issue.

But as part of my test, I also attempted to add null object references as items, and they still have a full visual tree underneath the VirtualizingCellsControl, unlike how the issue exhibits in my own application where the  VirtualizingCellsControl has no visual tree whatsoever.


Here are some screenshots from my original application.

Missing items in the SfDataGrid:

1_missing-items-in-SfDataGrid-UI.png

Items in the SfDataGrid missing visual tree content:

2_missing-items-in-visual-tree.png


After resizing the window:

4_items-appear-after-resize.png

5_items-present-in-visual-tree-after-resize.png


Attachment: SfDataGrid_Demo_test_8d47d3d4.zip


SG Santhosh Govindasamy Syncfusion Team March 3, 2025 12:36 PM UTC

Hi Naim William Kingston,

Thanks for your response.

As previously mentioned, we couldn't replicate the reported issue, and it has worked as expected.

After analyzing the reported issue, we believe it may occur on lower-end machines due to performance limitations, rendering delays, or outdated frameworks.

Factors to Consider:

  1. Hardware Limitations (Lower-End Machines)
    • Slower CPUs: Virtualization might not update UI elements fast enough, causing blank cells.
    • Lower RAM: If the system is under memory pressure, UI virtualization may not correctly render all elements.
  2. .NET Framework or .NET Version Differences
    • If you are using an older .NET version (such as .NET Core 3.1 or .NET Framework 4.6.2), there may be performance differences in SfDataGrid virtualization logic.
  3. Graphics Rendering Differences (WPF Hardware Acceleration)
    • Older machines might not fully support DirectX rendering, causing layout inconsistencies.
  4. Windows OS Version Differences
    • If your Windows version is older, there might be UI rendering differences.
    • Check your Windows version and update GPU drivers.

Solution to Try:

To resolve the issue, try the following solutions:

  1. Ensure UI Updates Happen on the Main Thread
    • If updating data asynchronously, force updates on the UI thread.

  1. Application.Current.Dispatcher.Invoke(() =>
  2.  {
  3.      var toRemove = this.collections[this.collectionIndex].Where(x => x.ID >= this.interval.lowIndex && x.ID <= this.interval.highIndex).ToList();
  4.      this.items.RemoveRange(toRemove);
  5.  
  6.      this.CollectionIndex = (this.collectionIndex + 1) % this.collections.Count;
  7.      this.Interval = this.GetRandomInterval(this.collections[this.collectionIndex].Count);
  8.  
  9.      var toAdd = this.collections[this.collectionIndex].Where(x => x.ID >= this.interval.lowIndex && x.ID <= this.interval.highIndex).ToList();
  10.      this.items.AddRange(toAdd);
  11.  });


2.Manually Refresh the DataGrid After Updating ItemsSource, Use the following methods:

    • sfDataGrid.View.Refresh();
      sfDataGrid.InvalidateMeasure();
      sfDataGrid.InvalidateArrange();
      sfDataGrid.UpdateLayout();

This should help resolve the issue. Let us know if you need further assistance.


Regards,
Santhosh.G


Loader.
Up arrow icon