
Sample Code
Code: Select all
Procedure GoToListItem(gad,i)
SetGadgetState(gad,-1) ; De-select any selected items.
SetGadgetState(gad,i-1) ; Now select the wanted item.
SendMessage_(GadgetID(gad),#LVM_ENSUREVISIBLE,i-1,0) ; And scroll to it.
EndProcedure
You may take a look into this example for MacOS which demonstrates how to programmatically move a row or column into a visible area.Andre wrote:Maybe I've missed the related post (but couldn't find it via searchfunction) - is such a function "always show selected item" (= scroll to a programmatically selected item) also possible for OS X?
Thanks, shardik!Shardik wrote:You may take a look into this example for MacOS which demonstrates how to programmatically move a row or column into a visible area.Andre wrote:Maybe I've missed the related post (but couldn't find it via searchfunction) - is such a function "always show selected item" (= scroll to a programmatically selected item) also possible for OS X?
Code: Select all
; http://www.purebasic.fr/english/viewtopic.php?f=13&t=60533
; combined PB help example with tipps from PB and Shardik by Andre
Procedure SelectnShowListItem(gad, item)
;SetGadgetState(gad, -1) ; De-select any selected items.
SetGadgetState(gad, item-1) ; Now select the wanted item.
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
SendMessage_(GadgetID(gad), #LVM_ENSUREVISIBLE, item-1, 0) ; And scroll to it.
CompilerElseIf #PB_Compiler_OS = #PB_OS_MacOS
CocoaMessage(0, GadgetID(gad), "scrollRowToVisible:", item-1)
CompilerElse
Debug "OS not supported (yet)!"
CompilerEndIf
EndProcedure
If OpenWindow(0, 100, 100, 300, 200, "ListIcon - Select and show a specific item", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 5, 5, 290, 190, "Name", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Address", 250)
For a = 1 To 20
AddGadgetItem(0, -1, "Mister " + Str(a) + Chr(10) + "Address " + Str(a))
Next
; Now select and show the 14th item:
SelectnShowListItem(0, 14)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf