ListIcon only one check and select independantly

Share your advanced PureBasic knowledge/code with the community.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

ListIcon only one check and select independantly

Post by Kwai chang caine »

Hello,

Starting to a code of SPARKIE
http://www.purebasic.fr/english/viewtop ... 829#p83829

It's surely a bad code, but that works, and for KCC, it's already a miracle :shock:
If that can serve at other

Code: Select all

Global OnlyOneCheck

Enumeration
 #Form0
 #ListIcon0
EndEnumeration
  
Procedure Callback(hWnd, msg, wParam, lParam)
 
 Static ElementChecked, ElementSelected, ElementUnChecked, Lock
 Result = #PB_ProcessPureBasicEvents
    
 Select msg
   
  Case #WM_NOTIFY
   
   If OnlyOneCheck And Not Lock
    
    *pnmhdr.NMHDR = lParam
     
    If *pnmhdr\code = #LVN_ITEMCHANGED
      
     *lvChange.NMLISTVIEW = lParam 
     
     If *lvChange\uNewState >>12 & $FFFF = 2
       
      ElementSelected = GetGadgetState(#ListIcon0)
      ElementChecked = *lvChange\iItem
      Lock = #True        
      
      For i = 0 To CountGadgetItems(#ListIcon0) - 1
       SetGadgetItemState(#ListIcon0, i, #False)
      Next
      
      If ElementSelected = ElementChecked
       
       SetGadgetItemState(#ListIcon0, ElementChecked, #PB_ListIcon_Checked|#PB_ListIcon_Selected)
       
      Else
       
       SetGadgetItemState(#ListIcon0, ElementChecked, #PB_ListIcon_Checked)
       
       If ElementSelected <> -1
        SetGadgetItemState(#ListIcon0, ElementSelected, #PB_ListIcon_Selected)
       EndIf
       
      EndIf 
         
      Lock = #False
       
     EndIf
     
    EndIf
    
   EndIf
    
 EndSelect
   
 ProcedureReturn Result 
         
EndProcedure

OpenWindow(#Form0, 679, 120, 180, 214, "New window ( 0 )",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
ListIconGadget(#ListIcon0, 10, 10, 160, 187, "Column0", 100, #PB_ListIcon_CheckBoxes)
SetWindowCallback(@Callback()) 

For i = 1 To 5
 AddGadgetItem(#ListIcon0, -1, "Item n° "+ Str(i))
Next

SetGadgetItemState(#ListIcon0, ElementChecked, #PB_ListIcon_Checked) ; Just for checking an item at the begining
OnlyOneCheck = #True ; Comment if you want check several item in the same time

Repeat
 Evenement = WaitWindowEvent()
Until Evenement = #PB_Event_CloseWindow
ImageThe happiness is a road...
Not a destination
yrreti
Enthusiast
Enthusiast
Posts: 546
Joined: Tue Oct 31, 2006 4:34 am

Re: ListIcon only one check and select independantly

Post by yrreti »

Nice one Kwaï chang caïne :)

Thanks for sharing this idea.

yrreti
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ListIcon only one check and select independantly

Post by Kwai chang caine »

Thanks to your kind compliment :D
ImageThe happiness is a road...
Not a destination
Post Reply