Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DataGrid virtualization not working properly?

I have a DataGrid which has a DataTable set as its ItemsSource. The DataTable holds 24 columns and ~1600 rows (actually I will have to load alot more rows later on, but for now this is troublesome enough).

Despite setting virtualization for columns and rows active, the DataGrid takes around 30 seconds to display those 1600 rows. After that, scrolling vertically works fine, horizontally is laggy, though you'd expect it the other way around.

If I run a memory profiler, I can verify that most of the memory used by the application comes from DataGridCells, Borders, ContentPresenters and Textblocks. To me, this indicates that the grid does not virtualize its rows properly.

Can anyone confirm that there's an issues with DataGrid's virtualization? Or is there some sort of infamous trap in the implementation of this control?

Looking forward to any kind of input/suggestions. Thanks :)

like image 282
i know nothing Avatar asked Feb 19 '13 12:02

i know nothing


2 Answers

I've solved the issue. My DataGrid was sitting inside a ScrollViewer, in which it would stretch infinitely. So it was fooled into thinking everything was visible, that's why it wouldn't virtualize its items. I removed the ScrollViewer (DataGrid has scrollbars on its own anyway) and it works flawlessly now.

like image 191
i know nothing Avatar answered Nov 15 '22 06:11

i know nothing


Hmm, ok I don't know why but obviously I've to add some glue text to post an answer here. Maybe, this SO answer will help you.

Edit

As additional advice I'd like to recommend you to think about your approach. Is it really necessary to add 1.6k+ items to a DataGrid? Perhaps you should think about deferred loading.

like image 45
DHN Avatar answered Nov 15 '22 07:11

DHN