Searching data is slow when autorefresh datagridview enabled RRS feed

  • Question

  • Hello! I'm trying to make autorefresh datagridview only when the insert/update function in my application is executed and it works.

    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.

    This is how I do autorefresh dgv:

    - I Add a global boolean variable in a module called autoRefreshGrid

    - Then at Insert/Update function I set this variable value to true

    - 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

    - then after refresh set the autoRefreshGrid to False

    Just for info, the Insert/Update function is executed by multiple thread so I add a timer to give an interval on every autorefresh

    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
      TmrRefreshGrid.Enabled = chkAutoRefresh.Checked
    End Sub

    This function is executed by autorefresh and refresh manually with or without filter.

    And this is Timer TmrRefreshGrid tick function

    If chkAutoRefresh.Checked = False Then Return
    If Not autoRefreshGrid Then Return
    autoRefreshGrid  = False

    Any solution please?

    Saturday, February 25, 2017 5:32 AM

All replies

  • Hello,

    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.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, February 25, 2017 8:10 AM
  • Yea it is always the same. 

    People try to optimize to get a pico second in memory, and than show to often to the screen. 

    The screen is the part which takes the most time.

    Be aware there are properties in the DataGridView to be able to limit the refresh as much as possible. 


    Saturday, February 25, 2017 5:30 PM
  • @Karen

    Sorry, maybe I should call it load to dgv than refresh. I use the refreshGrid function to load data to datagridview with/without filter. And the timer is just load the data when Autorefreshgrid is true. My application is not responding when refreshGrid function is executed with keyword and when the auto reload data is activated.

    Any idea?

    • Edited by Skypea Sunday, February 26, 2017 10:50 AM
    Sunday, February 26, 2017 10:50 AM
  • @Cor

    I agreed, when I set the datasource of DataGridView and when the data is more than 20 rows I got a delay for few seconds, but after that when I reload again I don't get a delay. I have not found yet which property it is. Any suggestions?

    Sunday, February 26, 2017 10:51 AM