MSFlex Grid Redraw causes scroll bar to move

akamikeym
01-25-2005, 04:45 AM
I am trying to make a Grid to display data that is returned from a ADO command as a recodset. This data is supposed to be refreshed every few seconds. I have implemented this where I turn off the grids Redraw, read the data from the record set into the grid in a loop, then turn Redraw back on. This works well for small grids but once the scroll bars are used the redraw command semes to cause the scroll bars to move whilst it loads. This happens if you are draging the scroll bar when it updates or if you are looking at the bottom of the grid (it moves the last line in the grid so that the scroll bar slightly overlaps it, no matter where the bottom line is on the screen).

Is there any way arround this. I have had a look for API solutions (trying to force the scroll pos into the same position as before the update once it is finished), but I could not find anything on doing it.

akamikeym
01-25-2005, 04:48 AM
Set rstYou = adocmdYou.Execute
'***
' Do calls for you
'***
grdYou.Redraw = False
grdYou.TextMatrix(0, 0) = "Date/Time"
grdYou.TextMatrix(0, 1) = "Company"
grdYou.TextMatrix(0, 2) = "Name"
grdYou.TextMatrix(0, 3) = "Phone No"
grdYou.TextMatrix(0, 4) = "Called for"
grdYou.TextMatrix(0, 5) = "Problem"
grdYou.TextMatrix(0, 6) = "Solution"
grdYou.TextMatrix(0, 7) = "Dealt with"
Row = 1
If grdYou.Rows <> rstYou.RecordCount + 1 Then
If rstYou.RecordCount > 0 Then
grdYou.Rows = rstYou.RecordCount + 1
Else
grdYou.Rows = 2
End If
End If
Do Until rstYou.EOF
grdYou.RowData(Row) = rstYou!ID
grdYou.TextMatrix(Row, 0) = Format(rstYou!DateTime, "dd/mm/yy / HH:MM")
grdYou.TextMatrix(Row, 1) = rstYou!Name
grdYou.TextMatrix(Row, 2) = rstYou!Forename & " " & rstYou!Surname
grdYou.TextMatrix(Row, 3) = rstYou!Telephone
grdYou.TextMatrix(Row, 4) = rstYou!TakenFor
grdYou.TextMatrix(Row, 5) = rstYou!Problem
grdYou.TextMatrix(Row, 6) = rstYou!Solution
If rstYou!DealtWith = False Then
grdYou.TextMatrix(Row, 7) = "No"
Else
grdYou.TextMatrix(Row, 7) = "Yes"
End If
Row = Row + 1
rstYou.MoveNext
Loop
grdYou.Redraw = True

Flyguy
01-25-2005, 07:54 AM
You can find/restore the current position using the .TopRow/.LeftCol properties

akamikeym
01-25-2005, 08:53 AM
You can find/restore the current position using the .TopRow/.LeftCol properties

OK I have just tried this and it has made no difference to the behaviour of the grid. So I will incluse my modified code and screenshots (I had to draw the pointer by hand where neccissary) of what is happening. Before and after pictures of the mouse being held down on the scroll bar before and after a reload of the data using redraw and of looking at the bottom row before and after a redraw.

Here is the code:


'***
' Get the calls for the current user
'***
Set rstYou = adocmdYou.Execute
'***
' Do calls for you
'***
grdYou.Redraw = False
ScrollPosY = grdYou.TopRow
ScrollPosX = grdYou.LeftCol
grdYou.TextMatrix(0, 0) = "Date/Time"
grdYou.TextMatrix(0, 1) = "Company"
grdYou.TextMatrix(0, 2) = "Name"
grdYou.TextMatrix(0, 3) = "Phone No"
grdYou.TextMatrix(0, 4) = "Called for"
grdYou.TextMatrix(0, 5) = "Problem"
grdYou.TextMatrix(0, 6) = "Solution"
grdYou.TextMatrix(0, 7) = "Dealt with"
Row = 1
If grdYou.Rows <> rstYou.RecordCount + 1 Then
If rstYou.RecordCount > 0 Then
grdYou.Rows = rstYou.RecordCount + 1
Else
grdYou.Rows = 2
End If
End If
Do Until rstYou.EOF
grdYou.RowData(Row) = rstYou!ID
grdYou.TextMatrix(Row, 0) = Format(rstYou!DateTime, "dd/mm/yy / HH:MM")
grdYou.TextMatrix(Row, 1) = rstYou!Name
grdYou.TextMatrix(Row, 2) = rstYou!Forename & " " & rstYou!Surname
grdYou.TextMatrix(Row, 3) = rstYou!Telephone
grdYou.TextMatrix(Row, 4) = rstYou!TakenFor
grdYou.TextMatrix(Row, 5) = rstYou!Problem
grdYou.TextMatrix(Row, 6) = rstYou!Solution
If rstYou!DealtWith = False Then
grdYou.TextMatrix(Row, 7) = "No"
Else
grdYou.TextMatrix(Row, 7) = "Yes"
End If
Row = Row + 1
rstYou.MoveNext
Loop
grdYou.TopRow = ScrollPosY
grdYou.LeftCol = ScrollPosX
grdYou.Redraw = True

akamikeym
02-04-2005, 06:57 AM
Sorry to bumb this post back up but I have hit a brick wall with it trying on my own and I can't belive that no one else has found this, or that no one has tried making a grid that periodicaly updates before.

Flyguy
02-04-2005, 08:40 AM
Can you reproduce this problem without using a DB recordset, so others can have a look at it?

akamikeym
02-04-2005, 09:05 AM
O.K. Here is an example of the problem I have just try scrolling down so that you can see the bottom line of this grid. Also try holding the scroll position with the mouse whilst it refreshes.

akamikeym
02-09-2005, 01:43 AM
I'm sorry to move this again but I'm sure some out there must know a way around this problem.

Flyguy
02-09-2005, 02:33 AM
Try to set .ScrollTrack = True

akamikeym
02-10-2005, 01:43 PM
Try to set .ScrollTrack = True

Sorry but trying that the example program still has exactly the same problem.

I am willing to try try working this a different way. I would like to continue using a stored procedure if at all possible which returns a record set. This being the case is there a way of 1st adding headings, I've never seen a way of doing this and then assigning the data source and re-asigning it once it is refreshed with:


Set rst = adocmd.execute

Flyguy
02-11-2005, 03:50 AM
You lost me :)

To get back to your original problem.
I don't think it's fair to call a control problem, it's afterall you who refreshes the control while user is scrolling through the data.
Maybe you should check whether the user has stopped scrolling for some seconds before you refresh the grid.

akamikeym
02-11-2005, 06:59 AM
You lost me :)
Maybe you should check whether the user has stopped scrolling for some seconds before you refresh the grid.

That would be OK if it only had an effect of the scroll bar but it also moves the grid up so the bottom row is partialy obscured when you are viewing it. So if I were to implement that approch the grid would never be updated whilst the user was looking at the bottom row. :eek:

I am however not trying to make things difficult for myself. :) So if this is not the standard approach to making an updating grid could someone point me in the right direction as my attempts at using data sources which get re-set were somewhat unsuccessfull. :-\

Flyguy
02-11-2005, 07:35 AM
That's when the .LeftCol and .TopRow properties are to be used.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum