How do I prevent window lock when binding large dataset to grid in C#?

点点圈 提交于 2021-01-28 12:23:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!