ListIconGadget which item checked?
ListIconGadget which item checked?
I have a list icon gadget with check box's... the problem is I want to know which item got checked or unchecked on the fly to avoid time consuming looping through the entire list.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
PB will send #PB_EventType_Change when you check/uncheck a box on a listicon gadget. You could record this 'on-the-fly' If you knew which item was affected but in native PB code I don't believe this is possible. (subject to correction of course, I could be wrong) On Windows, you would need to drop into API and send LVM_HITTEST to get this information when you receive a change event, then retrieve the checked state of that item:
Code: Select all
OpenWindow(0,0,0,640,320,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ListIconGadget(0,170,0,320,320,"stuff",315,#PB_ListIcon_CheckBoxes)
AddGadgetItem(0,-1, "stuff 0")
AddGadgetItem(0,-1, "stuff 1")
AddGadgetItem(0,-1, "stuff 2")
AddGadgetItem(0,-1, "stuff 3")
SetActiveGadget(0)
SetGadgetState(0,0)
Repeat
ev = WaitWindowEvent()
Select ev
Case #PB_Event_Gadget
If EventGadget() = 0 And EventType() = #PB_EventType_Change
GetCursorPos_(cp.POINT)
MapWindowPoints_(0,GadgetID(0),cp,1)
With hti.LVHITTESTINFO
\pt\x = cp\x
\pt\y = cp\y
\flags = #LVHT_ONITEM
EndWith
SendMessage_(GadgetID(0),#LVM_HITTEST,0,hti)
item = hti\iitem
If GetGadgetItemState(0,item) & #PB_ListIcon_Checked
Debug "item "+Str(item)+" checked"
Else
Debug "item "+Str(item)+" unchecked"
EndIf
EndIf
EndSelect
Until ev = #PB_Event_CloseWindow
BERESHEIT
Here's another Windows only solution :
Code: Select all
Procedure.i WinCallback(hWnd, uMsg, wParam, lParam)
Protected result = #PB_ProcessPureBasicEvents, *nmlv.NM_LISTVIEW
Select uMsg
Case #WM_NOTIFY
*nmlv = lParam
Select *nmlv\hdr\code
Case #LVN_ITEMCHANGED
If *nmlv\hdr\hWndFrom = GadgetID(0) And *nmlv\uOldState& #LVIS_STATEIMAGEMASK <> 0 And *nmlv\uNewState& #LVIS_STATEIMAGEMASK
Select (*nmlv\uNewState& #LVIS_STATEIMAGEMASK)>>12
Case 1
Debug "Item " + Str(*nmlv\iItem) + " has been un-checked!"
Case 2
Debug "Item " + Str(*nmlv\iItem) + " has been checked!"
EndSelect
EndIf
EndSelect
EndSelect
ProcedureReturn result
EndProcedure
OpenWindow(0,0,0,640,320,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
SetWindowCallback(@WinCallback())
ListIconGadget(0,170,0,320,320,"stuff",315,#PB_ListIcon_CheckBoxes)
AddGadgetItem(0,-1, "stuff 0")
AddGadgetItem(0,-1, "stuff 1")
AddGadgetItem(0,-1, "stuff 2")
AddGadgetItem(0,-1, "stuff 3")
SetActiveGadget(0)
SetGadgetState(0,0)
Repeat
ev = WaitWindowEvent()
Until ev = #PB_Event_CloseWindow
I may look like a mule, but I'm not a complete ass.