• Dan
  • Member Topic Starter

In my application I'm updating a grid from a database on a regular basis (currently every second while testing, so the issue is very obvious) to display the status of various tasks. As part of this I'm trying to ensure that the grid update doesn't shift focus away from the row the user is currently looking at, so I'm using code similar to the following to store the position of the current row before updating, and then adjusting the viewport after updating. However, if the grid is scrolled down and/or right before the refresh, this results in the scrollbars flickering due them not being included in the redraw handling via BeginUpdate/EndUpdate (I'm aware of the comment regarding this in the help, so I know it's not a bug). Is there any way to work around this, or is it simply not possible to deal with this?

With iGrid1

    lTopVisibleRow = .Sys(igSysCellsAreaStartRow)
    lTopVisibleRowY = .Sys(igSysCellsAreaStartRowTopY)
    lLeftVisibleCol = .Sys(igSysCellsAreaStartCol)
    lLeftVisibleColX = .Sys(igSysCellsAreaStartColLeftX)



    'rebuild grid here
    If lTopVisibleRow > 0 And lTopVisibleRow < .RowCount Then
        .EnsureVisibleRow lTopVisibleRow, igEnsVisRowTopForce, lTopVisibleRowY
        .EnsureVisibleCol lLeftVisibleCol, igEnsVisColLeftForce, lLeftVisibleColX
    End If

End With


I doubt we can enhance it.

If you want to make the same row visible in the viewport, does it mean that you can repopulate iGrid without calling the Clear method? Perhaps, you can write a more intelligent algorithm that only updates existing cells and add new required rows/remove unneeded rows instead of clearing the whole grid and adding rows again. I know, this is a harder way, but you are a programmer 😉
  • Dan
  • Member Topic Starter
Hi Igor,

With this particular application it's not quite that simple, as it could have thousands of rows being read in, and the values in all of those rows could be set to any value from outside of the application - some of the values are set by a service running on another server, and some are set by other copies of the GUI application. While it's possible to loop through all of the rows cross comparing with the current rows and updating cells this would be a lot slower that simply clearing the rows and adding them again in a single pass.

I've also got a colleague who uses the grid in a similar way, where the data is populated from a number of text files on a server that are continually being updated by hundreds of PCs on an assembly line (yes, it's messy, but it's a legacy system and it works :)) and again making multiple passes through the existing rows to find matching rows and update them, and then remove rows that no longer exist, will be somewhat slower than a single pass as it does now.

We can live with the scrollbars shifting, I was just hoping you might have some API code kicking around that can be used to temporarily disable the scrollbar refreshing. If I can figure out some convoluted Win32 API calls to handle it I'll let you know ;)

I too was bothered by the screen flickering and am successfully using the following API call from Access 2010

add this to a global module:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_SETREDRAW As Long = 11

use this in your grid updating procedure:
SendMessage Application.hWndAccessApp, WM_SETREDRAW, False, 0
'do stuff to update grid
SendMessage Application.hWndAccessApp, WM_SETREDRAW, True, 0
  • Dan
  • Member Topic Starter
Raymond, thanks for that snippet. I've got it working using the iGrid hWnd (that way the rest of the application is still responsive as the grid is being redrawn), and made sure the last line was placed before the iGrid1.EndUpdate call so that the grid was redrawn correctly, if it's placed afterwards then the .Refresh method needs to be called to force a redraw.


Thanks, Dan. That will be helpful when I need to prevent flickering in just the grid. In my case, I used the entire Access hWnd because Access is notorious for screen flickering and when I updated the grid, I was also loading some subforms and the flickering was ridiculous. In other words, I needed to stop the flickering in more places than just the grid.
  • Dan
  • Member Topic Starter
I haven't done any serious Access development since Access 2.0 (since then only used it for web databases up till Access 97, and as data conversion tool), so wasn't aware of it's flickering issue. Most of my development is in VB6 (lots of legacy code to support, and far easier to write small utility applications than VB.Net) with SQL Server for the database handling.