Page 1 of 1

Tick all checkboxes in a ListIconGadget?

Posted: Fri Jul 15, 2016 4:40 am
by Dude
I need to tick all checkboxes in a ListIconGadget at once, but preferably without iterating through all items one by one. In the snippet below, it selects all items in a ListIconBox, but doesn't tick their checkboxes. So is there something like this snippet that does it for checkboxes? I looked at https://msdn.microsoft.com/en-us/librar ... s.85).aspx but there's no constants that seem to do it. Thank you!

Code: Select all

lvi.LV_ITEM\mask=#LVIF_STATE
lvi\stateMask=#LVIS_SELECTED
lvi\state=#LVIS_SELECTED
SendMessage_(GadgetID(0),#LVM_SETITEMSTATE,-1,lvi)

Re: Tick all checkboxes in a ListIconGadget?

Posted: Fri Jul 15, 2016 4:44 am
by Keya
i dont have an exact answer for you sorry but here's what i use for selecting all checkboxes in a TreeGadget - maybe its similar if not the same? might only need to change #PB_Tree_Checked to #PB_ListIcon_Checked

Code: Select all

Procedure TreeDeselectAllItems(TreeId)
  Protected CurItem.i, CurState.i, ItemCnt.i = CountGadgetItems(TreeId) 
  If ItemCnt <= 0: ProcedureReturn: EndIf 
  For CurItem = 0 To ItemCnt-1
    CurState = GetGadgetItemState(TreeId, CurItem)
    CurState = CurState ! #PB_Tree_Checked
    SetGadgetItemState(TreeId, CurItem, CurState)
  Next
EndProcedure

Procedure TreeSelectAllItems(TreeId)
  Protected CurItem.i, CurState.i, ItemCnt.i = CountGadgetItems(TreeId) 
  If ItemCnt <= 0: ProcedureReturn: EndIf 
  For CurItem = 0 To ItemCnt-1
    CurState = GetGadgetItemState(TreeId, CurItem)
    CurState = CurState | #PB_Tree_Checked
    SetGadgetItemState(TreeId, CurItem, CurState)
  Next
EndProcedure

Re: Tick all checkboxes in a ListIconGadget?

Posted: Fri Jul 15, 2016 4:46 am
by Dude
Hi Keya! I just edited my post while you were replying, to say that I'd rather not go through all items one by one. :) We'll see if anyone else can come up with a one-hit answer.

Re: Tick all checkboxes in a ListIconGadget?

Posted: Fri Jul 15, 2016 4:50 am
by Keya
https://autohotkey.com/board/topic/8614 ... ndmessage/
; Function: LVM_SetItemState
; Description:
; Changes the state of an item in a ListView control.
; Parameters:
; p_Item - Zero-based index of the item. If set to -1, the state change is applied to all items.
Maybe that's the key!? I didn't think there was such an "apply to all items" WM message, but maybe -1 is all thats needed?!?! hope so! but i just noticed it looks like thats what you were trying in your first post

http://stackoverflow.com/questions/9342 ... -all-items

Code: Select all

[DllImport("user32.dll", EntryPoint = "SendMessage")]
  internal static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);

  // Select All
  SendMessage(listBox.Handle, 0x185, (IntPtr)1, (IntPtr)(-1));

  // Unselect All
  SendMessage(listBox.Handle, 0x185, (IntPtr)0, (IntPtr)(-1));
i looked up the 0x185 that the SendMessage call above is using - it's #LB_SETSEL, but i guess that Listbox msg wouldnt directly apply to your Listview/Listicon, so I think the "-1" is the way to go and that it's just a matter now of finding the correct message, lol

please let me know if it works so i can upgrade my (de)selection functions also... well, the Windows version anyway :) i think still have to enumerate through all items for Linux+OSX

Re: Tick all checkboxes in a ListIconGadget?

Posted: Fri Jul 15, 2016 6:51 am
by RASHAD
Hi Dude

Code: Select all

#LVIS_CHECKED = $2000
#LVIS_UNCHECKED = $1000

If OpenWindow(0, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
 
  ListIconGadget(0,  10, 10, 620,350, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect| #PB_ListIcon_CheckBoxes )
  ButtonGadget(1,10,370,100,20,"Set CheckBoxes")
 
  For c = 1 To 6
    AddGadgetColumn(0, c, "Column " + Str(c), 100)
  Next
  For r = 0 To 100
    AddGadgetItem(0, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
  Next
EndIf

Repeat
  Select WaitWindowEvent(1)
     
    Case #PB_Event_CloseWindow
      Quit = 1
     
    Case #PB_Event_Gadget
      Select EventGadget()               
        Case 1
            Run ! 1
            If Run = 1
                lvi.LV_ITEM\mask=#LVIF_STATE
                lvi\stateMask=#LVIS_STATEIMAGEMASK
                lvi\state=#LVIS_CHECKED
                SendMessage_(GadgetID(0),#LVM_SETITEMSTATE,-1,lvi)
                Debug GetGadgetItemState(0,2)
            Else               
                lvi.LV_ITEM\mask=#LVIF_STATE
                lvi\stateMask=#LVIS_STATEIMAGEMASK
                lvi\state=#LVIS_UNCHECKED
                SendMessage_(GadgetID(0),#LVM_SETITEMSTATE,-1,lvi)
                Debug GetGadgetItemState(0,2)
            EndIf
       
      EndSelect
  EndSelect
 
Until Quit = 1

Re: Tick all checkboxes in a ListIconGadget?

Posted: Fri Jul 15, 2016 6:55 am
by Keya
#LVM_SETITEMSTATE -1, ok cool! same as the autohotkey one afterall :)

Re: Tick all checkboxes in a ListIconGadget?

Posted: Fri Jul 15, 2016 7:30 am
by Dude
Thanks Rashad! Where did you find that #LVIS_CHECKED = $2000 constant, though? It's not on the MSDN page in my first post. :(

Re: Tick all checkboxes in a ListIconGadget?

Posted: Fri Jul 15, 2016 7:41 am
by RASHAD
Do not stop digging by reading MSDN only :P
What is so important that your problem is solved
It is not only #LVIS_CHECKED what you need but also #LVIS_STATEIMAGEMASK