在ProgressBar中显示DataGridView加载状态 [英] Display the DataGridView Loading Status in ProgressBar

查看:165
本文介绍了在ProgressBar中显示DataGridView加载状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





在我的Windows应用程序中,我在Datagridview中加载大量数据(使用数据源dgv.datasource = ds.Table(0)),它是花费更多时间加载,以便用户无法理解加载或应用程序被挂起所以我想在进度条中显示加载状态或用户可以理解数据正在加载的内容....



如果可能请给我示例代码....



请帮助我....

Hi,

In My windows application I am loading huge data in Datagridview ( using data source dgv.datasource=ds.Table(0) ),it is taking more time load so user cant understand it is loading or application hanged so i want to display the loading status in progressbar or something which user can understand that data is loading....

if possible please give me sample code....

Please Help me....

推荐答案

试试这个例子。



Try this as an example.

Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

    'Do NOT (ever) refer to form controls from this method
    'Keep it self contained

    'Add your background code

    'As you pass through each loop in your long runtime method do something like this
    BackgroundWorker1.ReportProgress(CInt((countsofar / totalofthingstodo) * 100))

End Sub

Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As System.Object, ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
    'Only ever refer to form controls from this method
    ProgressBar1.Value = e.ProgressPercentage
End Sub

Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As System.Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
    ProgressBar1.Value = ProgressBar1.Minimum
End Sub



在哪里说''''添加你的后台代码'',用它来填充DataSet(以编程方式创建,而不是表单控件),一旦后台工作程序完成,你可以将DataSet附加到DataGridView。



Mike


Where it says ''''Add your background code'', use that to fill a DataSet (created programatically, not a form control) and once the background worker has finished you can attach the DataSet to the DataGridView.

Mike


通过BackgroundWorker进行DataGridView加载,你需要填充你创建的对象BackgroundWorker线程而不是DGV直接(因为你不应该与BackgroundWorker线程中的UI线程交互),然后在完成时将数据复制到DGV。使用这个 [ ^ ]作为您的进度条和BackgroundWorker的ReportProgress功能,以更新它以显示进度和消息。



M
Do the DataGridView Loading via a BackgroundWorker, you''ll need to populate an object you create in the BackgroundWorker thread rather than the DGV directly (since you shouldn''t interact with the UI thread from the BackgroundWorker thread) and then copy the data to the DGV when it finishes. Use something like this[^] as your progress bar and the ReportProgress functionality of the BackgroundWorker to update it to show progress and a message.

M


这篇关于在ProgressBar中显示DataGridView加载状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆