Tick all checkboxes in a ListIconGadget?

Just starting out? Need help? Post your questions and find answers here.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Tick all checkboxes in a ListIconGadget?

Post 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)
Last edited by Dude on Fri Jul 15, 2016 4:45 am, edited 1 time in total.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Tick all checkboxes in a ListIconGadget?

Post 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
Last edited by Keya on Fri Jul 15, 2016 5:02 am, edited 2 times in total.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Tick all checkboxes in a ListIconGadget?

Post 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.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Tick all checkboxes in a ListIconGadget?

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: Tick all checkboxes in a ListIconGadget?

Post 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
Egypt my love
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: Tick all checkboxes in a ListIconGadget?

Post by Keya »

#LVM_SETITEMSTATE -1, ok cool! same as the autohotkey one afterall :)
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: Tick all checkboxes in a ListIconGadget?

Post 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. :(
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: Tick all checkboxes in a ListIconGadget?

Post 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
Egypt my love
Post Reply