7

I just got a question concerning the Microsofts PresentationFramework´s DataGrid:

I have an ObservableCollection<TestModel>. TestModel is a simple class with 20 Int properties... nothing more. In my test there are 50 Entries in my ObservableCollection. So overall I got 1000 cells (20*50). All of these cells are displayed at once, so there really is no virtualization possible.

This is my Grid:

<DataGrid AutoGenerateColumns="true" RowHeight="20" ItemsSource="{Binding DataGridModelSource}"/>

In my opinion 1000 cells to render is not very much... though it takes, depending on the system I am running this test on, about 1 to 3 seconds to render these 1000 cells. That´s quite a lot, isn't it?

I did the same test with some custom DataGrids like the one from C1, Infragistics, Mindscape or DX and the time to render these 1000 cells is reduced to about 100ms with all of these Grids.

So what is the point with the Microsoft DataGrid? Is there some way to improve the performance? Am I missing something?

Robert Nagel
  • 183
  • 1
  • 7
  • 1
    are you sure that 1-3 sec is rendering time, and not data loading time ? sure it is a lot, do you have converters, calcualtions? – Arsen Mkrtchyan Jun 12 '14 at 15:11
  • yes, i am measuring the data loading time.. thats about 50 ms. I dont have any converters or calculation. Thats just random int values, thrown in textblock columns. – Robert Nagel Jun 12 '14 at 15:15
  • 1
    DataGrid is "heavy" but 1-3 seconds does seem high. Do you need edit? ListView / GridView is much faster. – paparazzo Jun 12 '14 at 16:12
  • Well yea, unfortunately I need grouping,sorting and editing. – Robert Nagel Jun 12 '14 at 16:27
  • Why do you think virtualization isn't necessary? – Gayot Fow Jun 12 '14 at 18:06
  • Because that´s the customer´s request. He want´s to see all 50*20 cells on one big screen at once. And still...I don´t think that´s very much. Or am I wrong? – Robert Nagel Jun 12 '14 at 19:03
  • It's the only speed-up available for the DataGrid. Everybody wants it to go faster. I know of two companies who didn't like it so much they wrote their own binding engine. The speed is breathtaking, but it's a lot of work to develop. – Gayot Fow Jun 13 '14 at 05:18
  • Are you raising a `PropertyChanged` event for each individual cell? If so, are you calling that from your main thread? – user2588666 May 16 '15 at 06:55
  • I'm gonna put the blame on the ObservableCollection. If you're bound directly to it and adding items one by one, it might be causing too many recalculations. If you're not gonna add or remove items, which seems likely since you've said you have a fixed amount of items, I'd suggest changing to a lighter collection type. – almulo Jun 02 '15 at 15:44

1 Answers1

0

Use BindingList (https://msdn.microsoft.com/en-us/library/ms132679%28v=vs.110%29.aspx) instead of ObservableCollection. The problem is that you would have to implement grouping, sorting and so on on your own, but it should be faster.

Other things you could maybe do is to simplify the styles for your current theme. You could use https://wpfinspector.codeplex.com/ to maybe find something (even if it is the default windows theme)

Daniel Bişar
  • 2,663
  • 7
  • 32
  • 54