Page 1 of 1
ListIconGadget which item checked?
Posted: Thu Nov 20, 2008 3:16 am
by funnyguy
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.
Posted: Thu Nov 20, 2008 4:46 am
by netmaestro
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
Posted: Thu Nov 20, 2008 12:00 pm
by srod
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
Posted: Thu Nov 20, 2008 12:06 pm
by PB
On this subject, how can I make a ListIcon checkbox become checked or
unchecked if I just click the text next to it, rather than the checkbox itself?
Posted: Thu Nov 20, 2008 12:07 pm
by srod
Trap the mouse click and use SetGadgetItemState().
Posted: Thu Nov 20, 2008 12:19 pm
by PB
Of course! (Slaps forehead).
