ScrollView.ScrollPosition behavior

Andris

Active Member
Licensed User
Longtime User
While implementing ScrollView.ScrollPosition in my application, I ran across something interesting that might be of interest to others.

After listing a few hundred dates on a table within scrCalendar (a ScrollView), I needed to position scrCalendar to a particular date specified by TodayRow. I used the following code within Activity_Create:

For ....
(code that generates table)
Next ....

If TodayRow>=5 Then
scrCalendar.ScrollPosition=(TodayRow-5)*RowHeight​
Else
scrCalendar.ScrollPosition=0​
End If​

However, positioning did NOT happen! But, In trying to debug the code, I happened to add a message box before of the conditional statement:

For ....
(code that generates table)
Next ....

Msgbox("TodayRow=" & TodayRow,"")

If TodayRow>=5 Then
scrCalendar.ScrollPosition=(TodayRow-5)*RowHeight​
Else
scrCalendar.ScrollPosition=0​
End If​

Now. after clearing the message box, positioning worked (anyone have any explanation as to why?)! I then tried to simulate this same effect without the message box, and got the following to work, implementing a timer:

For ....
(code that generates table)
Next ....

Tmr.Initialize("ScrDly",10)
Tmr.Enabled=True


...............

Sub ScrDly_tick

Tmr.Enabled=False
If TodayRow>=5 Then
scrCalendar.ScrollPosition=(TodayRow-5)*RowHeight​
Else
scrCalendar.ScrollPosition=0​
End If​

End Sub​

I have a feeling there's a much easier way to do this, but if not (or if it's a bug), this is a quick workaround.
 

glouie

Member
Licensed User
Longtime User
I was stuck on the same issue, where if I put a msgbox or timer in between the ScrollPosition would change.

Does calling Doevents allow the scrollview to finish drawing before changing the position?

Thanks.
 
Upvote 0
Top