Page 1 of 1

Determine specific row on multiselect ListIcon right-click

Posted: Wed Jul 22, 2020 6:27 pm
by Dr Soong
This forum is a great repository of coding techniques, and I use it a lot! But, I've searched the forum and I've been unable to find a solution to my current problem.

I have a multiselect ListIcon gadget, and when multiple rows are selected, I want to be able to right-click on any particular row, and deselect it. I'm using the GetGadgetState function for the ListIcon gadget, but it always returns the first selected row in the list, not the specific one upon which the right-click was fired. I have not found any way to identify the specifically targeted row. I suspect there's a simple solution that I have just not found yet, but I have yet to find it. I'm running on a Windows machine, so if there is an API solution, that would work too. But I was hoping there was a native PB syntax to get the actual clicked row. :wink:

For example, in this code, if you click Item5, ctrl-click Item10, and ctrl-click Item15, and then right-click Item15, it is Item5 that becomes deselected, not Item15.

P.S. I've always had trouble with example code that uses "0" for multiple gadgets without explanation... When I was a newbie, it always made deciphering which "0" referred to which gadget a challenge. So I was a little more verbose in this example code, but hopefully helps it be clearer for any other readers.

Code: Select all

#WindowGadgetNum     = 0
#ListiconGadgetNum   = 0
#PopupMenuNum        = 0
#DeselectMenuItemNum = 0
If OpenWindow(#WindowGadgetNum, 100, 100, 300, 500, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   ListIconGadget(#ListiconGadgetNum, 5, 5, 290, 490, "Test", 100, #PB_ListIcon_MultiSelect)
   For i.i = 0 To 19
     AddGadgetItem(#ListiconGadgetNum, -1, "Item"+i)
   Next i
   Repeat
     Event = WaitWindowEvent()
     Select event
       Case #PB_Event_Gadget
         Select EventType()
           Case #PB_EventType_RightClick
             selectedItem.i = GetGadgetState(#ListiconGadgetNum)
             SetGadgetItemState(#ListiconGadgetNum,selectedItem,#False) ;deselect selected item
         EndSelect
     EndSelect
   Until Event = #PB_Event_CloseWindow
 EndIf

Re: Determine specific row on multiselect ListIcon right-cli

Posted: Wed Jul 22, 2020 8:36 pm
by Shardik
In Windows you only have to change

Code: Select all

             selectedItem.i = GetGadgetState(#ListiconGadgetNum)
to

Code: Select all

             selectedItem.i = SendMessage_(GadgetID(#ListiconGadgetNum), #LVM_GETSELECTIONMARK, 0, 0)

Re: Determine specific row on multiselect ListIcon right-cli

Posted: Wed Jul 22, 2020 10:44 pm
by Dr Soong
That's awesome, Shardik! Thank you so much! That's just what I needed!