问题
I've got a window that will be filled with a grid. On a background thread I asynchronously retrieve data tables from several different servers. These tables I then need to display in the grid. I have a progress bar from the background thread displaying while I'm establishing connections and pulling the data, but when the grid is being filled the UI thread is (understandably) blocked. Therefore, the progress bar stalls and it looks like the window is frozen. Filling the grid can take anywhere from 20 seconds to 2 minutes depending on the data set (Yes, it's huge; No, I can't make it smaller sadly.)
What I want to know is without using any Linq or custom libraries how can I bind the data without blocking the UI (keep the progress bar moving), then display the whole thing in one go?
I don't necessarily require concrete code, but more "This is what to do" with some logic behind it.
The key, really, is to load the data into the grid while not blocking the UI thread so a progress indicator can be displayed (and active) while it is ongoing.
Thank you all!
回答1:
You can use VirtualMode=true;
and then you can handle the CellValueNeeded
event
here an example explaining how to do it Implementing Virtual Mode with Just-In-Time Data Loading in the Windows Forms DataGridView Control
also, you can refer to this Performance Tuning in the Windows Forms DataGridView Control
hope it will help you
来源:https://stackoverflow.com/questions/29219227/how-do-i-prevent-window-lock-when-binding-large-dataset-to-grid-in-c