I found some example code that appears to make this happen... but not for me! If you can spare a minute please look at the attached... which is a minimal version of the big program, and tell me where I have been real stupid!
Code: Select all
; German forum: http://www.purebasic.fr/german/viewtopic.php?t=906&highlight=
; Author: Falko (updated for PB 4.00 by Andre)
; Date: 07. December 2004
; OS: Windows
; Demo: No
; Move scrollbar of a ListIcon by command... Original version
#MyWindow = 0
#MyGadget = 1
If OpenWindow(#MyWindow,100,100,300,500,"Works OK.",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(#MyWindow))
ListIconGadget(#MyGadget,5,5,290,490,"Name",150,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(#MyGadget,1,"Adresse",250)
For i=1 To 500
AddGadgetItem(#MyGadget,-1,Str(i)+" Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
Next i
For A=1 To 401
SetScrollPos_(GadgetID(#MyGadget),#SB_VERT,A,#True)
SendMessage_(GadgetID(#MyGadget),#WM_VSCROLL,#SB_LINEDOWN,0)
Delay(10)
Next A
For A=401 To 1 Step -1
SetScrollPos_(GadgetID(#MyGadget),#SB_VERT,A,#True)
SendMessage_(GadgetID(#MyGadget),#WM_VSCROLL,#SB_LINEUP,0)
Delay(10)
Next A
Repeat
EventID = WindowEvent()
Until EventID = #PB_Event_CloseWindow And EventWindow() = #MyWindow
EndIf
EndIf
FreeGadget(#MyGadget)
CloseWindow(#MyWindow)
Delay(1000)
; My version... writes all data, positions scrollbar. Then finds scrollbar, clears data, re-writes data to list and tries to fix
; the scrollbar and text to original position.
#MyWindow = 0
#MyGadget = 1
If OpenWindow(#MyWindow,100,100,300,500,"Problem. Read comments.",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
If CreateGadgetList(WindowID(#MyWindow))
ListIconGadget(#MyGadget,5,5,290,490,"Name",150,#PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
; Write some initial data to gadget
For i = 0 To 499
AddGadgetItem(#MyGadget,-1,Str(i)+" Harry Rannit"+Chr(10)+"Original")
Next
; Position scroll bar... why does the text not move to proper position?
; Falko's example makes it move! (Apparently)
SetScrollPos_(GadgetID(#MyGadget),#SB_VERT,150,#True) ; Position 150
SendMessage_(GadgetID(#MyGadget),#WM_VSCROLL,#SB_LINEDOWN,0)
; Get the scroll bar position
KeepPosition = getScrollPos_(GadgetID(#MyGadget),#SB_VERT) - 1
MessageRequester("Test","Note position = "+Str(KeepPosition))
; ==========================================================================
; Erase and Rewrite the data. (In the real app it is refreshed and some columns change)
ClearGadgetItemList(#MyGadget)
For i = 0 To 499
AddGadgetItem(#MyGadget,-1,"")
SetGadgetItemText(#MyGadget,i,Str(i)+" Version 2",0)
Next
; Set the scroll bar... Again the text does not move
SetScrollPos_(GadgetID(#MyGadget),#SB_VERT,KeepPosition,#True)
SendMessage_(GadgetID(#MyGadget),#WM_VSCROLL,#SB_LINEDOWN,0)
; Wait for exit... Try scrolling the bar several times and watch carefully.
; For a while there are lots of blank lines at the top of the screen and
; then they disappear... watch the numbers.
Repeat
EventID = WindowEvent()
Until EventID = #PB_Event_CloseWindow And EventWindow() = #MyWindow
EndIf
EndIf