You may use the following cross-platform procedure SelectExplorerListRow() which uses the appropriate API functions of MacOS, Linux and Windows to select a row in an ExplorerListGadget:MuuSer wrote:I have implemented this feature now by Windows API, but this means, that it’s not crossportable.
Code: Select all
EnableExplicit
Procedure SelectExplorerListRow(ExplorerListID.I, RowIndex.I)
If RowIndex < CountGadgetItems(ExplorerListID)
SetActiveGadget(ExplorerListID)
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Protected TreePath.I = gtk_tree_path_new_from_indices_(RowIndex, -1)
gtk_tree_view_set_cursor_(GadgetID(ExplorerListID), TreePath, 0, #False)
CompilerCase #PB_OS_MacOS
Protected IndexSet.I
IndexSet = CocoaMessage(0, CocoaMessage(0, 0, "NSIndexSet alloc"),
"initWithIndex:", RowIndex)
CocoaMessage(0, GadgetID(ExplorerListID),
"selectRowIndexes:", IndexSet,
"byExtendingSelection:", #NO)
CocoaMessage(0, IndexSet, "release")
CompilerCase #PB_OS_Windows
Protected Item.LVITEM
Item\mask = #LVIF_STATE
Item\state = #LVIS_SELECTED
Item\stateMask = #LVIS_SELECTED
SendMessage_(GadgetID(ExplorerListID), #LVM_SETITEMSTATE, RowIndex, @Item)
CompilerEndSelect
EndIf
EndProcedure
OpenWindow(0, 270, 100, 400, 200, "ExplorerListGadget")
; ---- Attention: The flag #PB_Explorer_AlwaysShowSelection is necessary to
; see a selected entry in Windows OS
ExplorerListGadget(0, 10, 10, 380, 180, "/", #PB_Explorer_AlwaysShowSelection)
SelectExplorerListRow(0, 0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow