启用自动刷新数据网格视图时,搜索数据速度很慢 [英] Searching data is slow when autorefresh datagridview enabled
问题描述
你好!我试图仅在执行应用程序中的插入/更新功能并且可以正常工作时,才使autorefresh datagridview成为可能.
Hello! I'm trying to make autorefresh datagridview only when the insert/update function in my application is executed and it works.
我的问题是当我搜索数据时,当我在搜索文本框中输入关键字并按Enter时,加载过程很慢,并且我的应用程序几秒钟没有响应.但是,当我关闭自动刷新并搜索数据时,它就会正常运行.
My problem is when I search data, when I input the keyword and press enter in seach textbox, then the load process is slow, and my application is not responsing for few seconds. But when I turn off autorefresh and I search data, then it run normally.
这是我自动刷新dgv的方法:
This is how I do autorefresh dgv:
-我在名为autoRefreshGrid的模块中添加了全局布尔变量
- I Add a global boolean variable in a module called autoRefreshGrid
-然后在插入/更新"功能中,将此变量值设置为true
- Then at Insert/Update function I set this variable value to true
-在主要形式中,我添加了一个间隔为1500的计时器.该计时器用于检查autoRefreshGrid是否为true,然后刷新dgv
- And in main form, I add a timer with interval 1500. This timer is to check if autoRefreshGrid is true then it refresh the dgv
-然后刷新后,将autoRefreshGrid设置为False
- then after refresh set the autoRefreshGrid to False
仅供参考,Insert/Update函数是由多个线程执行的,因此我添加了一个计时器,以便在每次自动刷新时提供一个间隔
Just for info, the Insert/Update function is executed by multiple thread so I add a timer to give an interval on every autorefresh
这是我的refreshDgv函数:
and this is my refreshDgv function:
Private Sub refreshGrid(ByVal keyword As String)
AutorefreshGrid = False
TmrRefreshGrid.Enabled = False
' load data using SqlDataAdapter and DataSet
' then set DGV datasource to DataSet table
loadData(keyword)
TmrRefreshGrid.Enabled = chkAutoRefresh.Checked
End Sub
此功能通过自动刷新执行,并在有或没有过滤器的情况下手动刷新.
This function is executed by autorefresh and refresh manually with or without filter.
这是Timer TmrRefreshGrid刻度功能
And this is Timer TmrRefreshGrid tick function
If chkAutoRefresh.Checked = False Then Return
If Not autoRefreshGrid Then Return
autoRefreshGrid = False
refreshGrid(txtSearch.Text)
请问有解决方案吗?
推荐答案
你好,
在DataGridView中搜索数据时,您永远不需要刷新DataGridView.在数据库表中搜索数据时,只需加载DataGridView.在任何情况下,计时器都是错误的方法.
You should never need to refresh a DataGridView when searching for data in a DataGridView. When searching for data in a database table(s) you should simply load the DataGridView. A timer in any case is the wrong way too go.
这篇关于启用自动刷新数据网格视图时,搜索数据速度很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!