I have tested the example successfully on these operating systems:
- MacOS X 10.6.8 (Snow Leopard) with PB 5.41 x86 and x64
- Ubuntu 14.04 x64 with KDE and PB 5.41 x64
- Windows 7 SP1 with PB 5.41 x86 and x64
Code: Select all
EnableExplicit
#RowCount = 10
; ----- Create an array that will contain the indices of the selected items
CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
Dim RowIndex.I(#RowCount - 1) ; Has to be Long in x86 and Quad in x64!
CompilerElse
Dim RowIndex.L(#RowCount - 1)
CompilerEndIf
Procedure.I GetSelectedRows(GadgetID.I)
Protected SelectedRowsCount.I
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux
Shared RowIndex.L()
Protected i.I
Protected IndexList.I
Protected Path.I
Protected Selection.I
Selection = gtk_tree_view_get_selection_(GadgetID(GadgetID))
If Selection
IndexList = gtk_tree_selection_get_selected_rows_(Selection, 0)
If IndexList
SelectedRowsCount = g_list_length_(IndexList)
For i = 0 To SelectedRowsCount - 1
Path = g_list_nth_data_(IndexList, i)
RowIndex(i) = PeekI(gtk_tree_path_get_indices_(Path))
Next i
g_list_free_(IndexList)
EndIf
EndIf
CompilerCase #PB_OS_MacOS
Shared RowIndex.I()
Protected IndexSet.I
IndexSet = CocoaMessage(0, GadgetID(GadgetID), "selectedRowIndexes")
SelectedRowsCount = CocoaMessage(0, IndexSet,
"getIndexes:", @RowIndex(),
"maxCount:", ArraySize(RowIndex()) + 1,
"inIndexRange:", 0)
CompilerCase #PB_OS_Windows
Shared RowIndex.L()
SelectedRowsCount = SendMessage_(GadgetID(0), #LB_GETSELCOUNT, 0, 0)
If SelectedRowsCount > 0
SendMessage_(GadgetID(GadgetID), #LB_GETSELITEMS, SelectedRowsCount,
@RowIndex())
EndIf
CompilerEndSelect
ProcedureReturn SelectedRowsCount
EndProcedure
Define i.I
Define SelectedRowsCount.I
OpenWindow(0, 100, 100, 270, 195, "Detect multiselected items")
ListViewGadget(0, 10, 10, 250, 135, #PB_ListView_MultiSelect)
ButtonGadget(1, 60, 155, 140, 25, "List selected items")
For i = 1 To #RowCount
AddGadgetItem (0, -1, "Row " + Str(i))
Next
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 1
SelectedRowsCount = GetSelectedRows(0)
Debug "Number of selected rows: " + SelectedRowsCount
If SelectedRowsCount > 0
For i = 0 To SelectedRowsCount - 1
Debug RowIndex(i) + 1
Next i
EndIf
EndIf
EndSelect
ForEver