I need some help on a thing that I can't resolve.
我需要一些无法解决的问题的帮助。
I've a Windows Form with a DataGridView who is populated with a large amount of data. This data is stored in a SQL Server Database and retrieved by a simple piece of ADO.NET code.
我有一个带有DataGridView的Windows窗体,其中填充了大量数据。此数据存储在SQL Server数据库中,并由一段简单的ADO.NET代码检索。
I'm already using the BackGroundWorker class to perform this kind of operation but the form still freezes for 1-2 second.
我已经使用BackGroundWorker类来执行这种操作,但表单仍然会冻结1-2秒。
Is there a way to delay the showing of the form? Like a show form only when all data in loaded? I've tried to make it not visible or to use Hide() and Show() method but still not have any results.
有没有办法延迟表格的显示?只有在加载所有数据时才显示表单?我试图让它不可见或使用Hide()和Show()方法,但仍然没有任何结果。
2 个解决方案
#1
0
Remove InitializeComponent();
from constructor of your form and call this method when data has loaded
删除InitializeComponent();从表单的构造函数,并在数据加载时调用此方法
#2
0
I've found a easy work-around. Change the modifiers of the BackGroundWorker to public. Create the instance of the form, run Form.CreateControl() and call the BackGroundWorker.RunWorkerAsync() method. In the DoWork event I put: data retrieving and population of the controls (DataGridView, combobox and textbox). In the RunWorkerCompleted just the Form.Show() method. That's all. Is this a nice solution?
我找到了一个简单的解决方法。将BackGroundWorker的修饰符更改为public。创建表单的实例,运行Form.CreateControl()并调用BackGroundWorker.RunWorkerAsync()方法。在DoWork事件中我提出:数据检索和控件的填充(DataGridView,组合框和文本框)。在RunWorkerCompleted中只是Form.Show()方法。就这样。这是一个很好的解决方案?
#1
0
Remove InitializeComponent();
from constructor of your form and call this method when data has loaded
删除InitializeComponent();从表单的构造函数,并在数据加载时调用此方法
#2
0
I've found a easy work-around. Change the modifiers of the BackGroundWorker to public. Create the instance of the form, run Form.CreateControl() and call the BackGroundWorker.RunWorkerAsync() method. In the DoWork event I put: data retrieving and population of the controls (DataGridView, combobox and textbox). In the RunWorkerCompleted just the Form.Show() method. That's all. Is this a nice solution?
我找到了一个简单的解决方法。将BackGroundWorker的修饰符更改为public。创建表单的实例,运行Form.CreateControl()并调用BackGroundWorker.RunWorkerAsync()方法。在DoWork事件中我提出:数据检索和控件的填充(DataGridView,组合框和文本框)。在RunWorkerCompleted中只是Form.Show()方法。就这样。这是一个很好的解决方案?