Please try my following true cross-platform solution which displays the row and column of a clicked cell. I have tested it successfully on these operating systems:Mindphazer wrote:Though I wish you could find a cross platform way
- MacOS 10.6.8 (Snow Leopard) with PB 5.31 x86 and x64
- Ubuntu 14.04 x64 Unity with PB 5.31 x64
- Windows XP SP3 with PB 5.31 x86
- Windows 7 x64 SP1 with PB 5.31 x86 and x64
Not quite true: the Windows code is taken from this old code example from srod and doesn't require a callback...falsam wrote:The only option is THE CallBack.

Code: Select all
EnableExplicit
Procedure.I GetSelectedColumn(WindowID.I, ListIconID.I)
Protected SelectedColumn.I
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Linux ; ------------------------------------------------
Protected ColumnList.I
Protected ColumnObject.I
Protected Iter.I
Protected Path.I
Protected TreeStore.I
If gtk_tree_view_get_cursor_(GadgetID(ListIconID), @Path, @ColumnObject)
TreeStore = gtk_tree_view_get_model_(GadgetID(ListIconID))
If gtk_tree_model_get_iter_(TreeStore, @Iter, Path)
If Path <> 0 And ColumnObject <> 0
ColumnList = gtk_tree_view_get_columns_(GadgetID(ListIconID))
SelectedColumn = g_list_index_(ColumnList, ColumnObject)
g_list_free_(ColumnList)
EndIf
EndIf
EndIf
CompilerCase #PB_OS_MacOS ; ------------------------------------------------
Protected CursorLocation.NSPoint
CursorLocation\x = WindowMouseX(WindowID)
CursorLocation\y = WindowHeight(WindowID) - WindowMouseY(WindowID)
CocoaMessage(@CursorLocation, GadgetID(ListIconID),
"convertPoint:@", @CursorLocation, "fromView:", 0)
SelectedColumn = CocoaMessage(0, GadgetID(ListIconID),
"columnAtPoint:@", @CursorLocation)
CompilerCase #PB_OS_Windows ; ----------------------------------------------
Protected CursorLocation.POINT
Protected HitInfo.LVHITTESTINFO
GetCursorPos_(CursorLocation)
MapWindowPoints_(0, GadgetID(ListIconID), CursorLocation, 1)
Hitinfo\pt\x = CursorLocation\x
HitInfo\pt\y = CursorLocation\y
SendMessage_(GadgetID(ListIconID), #LVM_SUBITEMHITTEST, 0, HitInfo)
SelectedColumn = HitInfo\iSubItem
CompilerEndSelect
ProcedureReturn SelectedColumn
EndProcedure
OpenWindow(0, 200, 100, 304, 107, "Detect clicked cell")
ListIconGadget(0, 5, 5, WindowWidth(0) - 10, WindowHeight(0) - 10, "Column 0",
95, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
AddGadgetColumn(0, 1, "Column 1", 95)
AddGadgetColumn(0, 2, "Column 2", 95)
AddGadgetItem(0, -1, "0,0" + #LF$ + "0,1" + #LF$ + "0,2")
AddGadgetItem(0, -1, "1,0" + #LF$ + "1,1" + #LF$ + "1,2")
AddGadgetItem(0, -1, "2,0" + #LF$ + "2,1" + #LF$ + "2,2")
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
If EventGadget() = 0 And EventType() = #PB_EventType_LeftClick
Debug "Clicked cell: " + GetGadgetState(0) + "," + GetSelectedColumn(0, 0)
EndIf
EndSelect
ForEver