PB 5.4: How to detect ListIcon checkbox event?

Just starting out? Need help? Post your questions and find answers here.
Joris
Addict
Addict
Posts: 890
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by Joris »

I think you need to replace GadgetID(1) with *uMsg\idFrom.

So tst = ListIconGadget(1, 10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect)
becomes :

Code: Select all

Procedure WndProc(hwnd, uMsg, wParam, lParam)
    Select uMsg
      Case #WM_NOTIFY
               *uMsg.NMHDR = lParam                                                                     
              If *uMsg\idFrom = tst And *uMsg\code = #NM_CLICK
                 *Li.NMITEMACTIVATE = lParam
                 Program\CurrentCheckedRow = *Li\iItem
              EndIf

    EndSelect
   ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
It wont block dragndrop but doesn't give errors on GadtgetId()...
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

PB 5.4: How to detect ListIcon checkbox event?

Post by HanPBF »

Code: Select all


EnableExplicit


Declare		onLIGCallback()

define NrWin = OpenWindow(#PB_Any, 0, 0, 640, 400, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

if NrWin
	global NrLIG = ListIconGadget(#PB_Any,  10, 10, 620,380, "Column 0", 100, #PB_ListIcon_GridLines|#PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect|#PB_ListIcon_ThreeState)

	define c
	define r
	
	For c = 1 To 6
    AddGadgetColumn(NrLIG, c, "Column " + Str(c), 100)
  Next
  For r = 0 To 1000
    AddGadgetItem(NrLIG, r, "  Item "+Str(r)+Chr(10)+"Item "+Str(r)+Chr(10)+"Item 3"+Chr(10)+"Item 4")
    
    SetGadgetItemData(NrLIG, r, #PB_ListIcon_Inbetween)
    SetGadgetItemState(NrLIG, r, #PB_ListIcon_Inbetween)    
  Next
endif


BindGadgetEvent(NrLIG, @onLIGCallback())



Repeat
  define NrWindowEvent = WaitWindowEvent()
  
  if NrWindowEvent=#PB_Event_CloseWindow
  	break
  endif
  
 forever
  
  
Procedure	onLIGCallback()
	Protected NrGadget 		= EventGadget()
	Protected NrEvenType 	= EventType()
	Protected i
	Protected	WasChecked 
	Protected	IsChecked 
	
	
	if GadgetType(NrGadget)=#PB_GadgetType_ListIcon
		for i = 0 to CountGadgetItems(NrGadget)			
			WasChecked = GetGadgetItemData(NrGadget, i)
			IsChecked= GetGadgetItemState(NrGadget, i)
			
			if IsChecked<>WasChecked
				debug "Checkbox row " + Str(i) + " changed from " + Str(WasChecked) + " to " + str(IsChecked)
				
				SetGadgetItemData(NrGadget, i, IsChecked)
			endif
		next i
	endif  
EndProcedure ; onLIGCallback()


With 10000 rows it gets slow and laptop gets a little noisier...
Choosing an array to store the state could be faster.

The window callback solutions are always very smart; but when You check the states it's easier to change the handling to not check each change (pressing save button or similar). Callbacks look always clever in a small example organisation gets harder and using global variables...
SeregaZ
Enthusiast
Enthusiast
Posts: 629
Joined: Fri Feb 20, 2009 9:24 am
Location: Almaty (Kazakhstan. not Borat, but Triple G)
Contact:

Re: PB 5.4: How to detect ListIcon checkbox event?

Post by SeregaZ »

Joris, i try to explane by image. make new select and in same time hold mouse button and move down. it work just once every new select.
Image
Post Reply