question

ShmoofySoft avatar image
1 Vote"
ShmoofySoft asked Viorel-1 commented

WPF DataGrid - SelectAll performance is erratic

I'm encountering a problem where I have a WPF DataGrid bound to a List of structs. If I use SelectAll to select all the rows, sometimes it highlights all the rows instantly regardless if there are hundreds of thousands, and sometimes (with exactly the same data) the SelectAll can take minutes or longer. It's very strange - I can execute the same program again and again with the same data but the SelectAll performance is hugely erratic.

If no one has ever heard of this, I'll try to reproduce it in some code, but it's annoyingly random and thus hard to reproduce. Thanks.

windows-wpfdotnet-wpf-xaml
· 14
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello, I have the same issue here on .Net 4.8

I found out two things:
- If the window with the DataGrid opens and the only thing I do is to click in the Grid and Ctrl+a, everything is fine.
If I do anything else e.g. open a dropdown, then the selection is slow.
- If I overwrite the Equals() method inside my entry objects, I can see in the debugger that it gets called a lot in that time

I'm not 100% sure, but maybe that is the same problem and in that case this information might help?
And I would be happy, if a solution can get found for this. Even if I have to overwrite the observable collection.

1 Vote 1 ·

Hi, yes I tried it on 4.8 too and it's the same problem. I have a request with Microsoft, so maybe they will get back to us:

https://developercommunity.visualstudio.com/t/WPF-DataGrid-has-erratic-SelectAll-perfo/1516287?entry=problem&ref=native&refTime=1630169722852&refUserId=14ddeccf-2d8e-6c9c-8cfa-93c286224d42


0 Votes 0 ·

Is there any data that might require extra processing? Are you sure there is not other processing occurring in the system that could cause it?

0 Votes 0 ·

Hi, thanks for the comment. I use a List of structs as the performance in a DataGrid (excluding SelectAll obviously) seems better in comparison to an ObservableCollection. As a test I tried switching to ObservableCollection and also tried a List of classes but the issue with SelectAll remains. It's maddening! I feel like I've checked everything I can check. There's no other processing or threads running. As far as I know, SelectAll runs on the UI thread, so the UI pauses while it does its work. Sometimes that pause is instant, even with (say) 200,000 rows or more. Other times it takes 10 seconds to select just 30,000 rows. The data rows are not particularly wide (12 columns, a mix of int and strings), and I tried it with a reduced set of columns, but it still exhibits the problem. But only sometimes... which is the annoying part. There's no pattern to it - I can run it with exactly the same data again and again, and the problem pops up every few executions, and it happens in both debug and release mode. I'm targeting .NET 4.6.2 and running a pretty good machine, Ryzen 3950 with 32GB memory, no issues with anything else. I even spun up a VM to see if it was something with my environment. The VM was a basic install of Windows 10, but same problem there too. I can't seem to find anyone having similar issues.

0 Votes 0 ·

If you have a sample project, which shows the problem and includes a DataGrid and a large list of some data, you can publish it on your OneDrive or other services.

0 Votes 0 ·
Show more comments

Simple example here, on Google Drive and documented the code. Any help would be appreciated!

https://drive.google.com/file/d/1_9d2aIPsTAWK5xVIF8xWIc6dlYGohncN/view?usp=sharing

0 Votes 0 ·

I tried your example and I get poor performance every time I select all and each time I select a row after a select all. There are others reporting poor performance in similar situations and I see no easy answer.

0 Votes 0 ·
Show more comments

@ ShmoofySoft , are you able to solve this issue ? I am facing same issue .
Please suggest solution here if any .

0 Votes 0 ·
Viorel-1 avatar image Viorel-1 vikashgupta-2954 ·

If you are facing the same issue, then consider using classes instead of structures.


0 Votes 0 ·

1 Answer

SimpleSamples avatar image
0 Votes"
SimpleSamples answered ShmoofySoft commented

Go to the Help menu in Visual Studio. From there you can send feedback. First search for existing feedback relative to the problem. I am currently unable to search; Microsoft won't sign me in plus I am using VS 2017.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Job done, thanks. Be interesting to see what comes out of it.

0 Votes 0 ·