Detect if checkbox is clicked in ListIconGadget?

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

UPDATED

I want to get the row state(index number) of a ListIconGadget when I press a checkbox in a ListIconsGadget.

Because now I have first select the full row then press the checkbox to detect on which row the checkbox has been pressed.

But I want to get the pressed checkbox row index nomatter what the selected full row is.

Just press only the checkbox, you then see that no row state is returned.,only if you first select one (click on text) but that is what I want.

Just run the example below and you will see.

Any suggestions are welcome

Code: Select all

If OpenWindow(0, 100, 100, 295, 360, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")

If CreateGadgetList(WindowID())
ListIconGadget(0, 10, 10, 168, 250, "Fields", 164, #PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect) 
AddGadgetItem(0,-1,"Field1")
AddGadgetItem(0,-1,"Field2")
EndIf

  Repeat
   EventID.l = WaitWindowEvent()

    If EventID = #PB_EventCloseWindow  ; If the user has pressed on the close button
      Quit = 1
    EndIf
      
    If EventID = #PB_EventGadget
      Select EventGadgetID()
      
      Case 0
        If EventType() = #PB_EventType_LeftClick    
        state= GetGadgetState(0)   
        state1= GetGadgetItemState(0,0)
        MessageRequester("Info","Row: " +Str(state) + " Item State: " + Str(state1),0)
        EndIf
      EndSelect
    EndIf  
    
  Until Quit = 1
  
EndIf

End


Using Windows 98 SE
Registered PB version : 3.40 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by SoulTaker.

Hi cor,

I worked with your code and added a Procedure to return the CheckBox Row Selection.

It's not perfect but works, there is a small bug when the row is selected but this should give you an idea of how its done. The file is on my Web Site for all.

ListIconRow.Zip

http://www.PureBasicBeginner.com


Abit BD7-II Raid P4 1.9 gHz 384 Ram Xtasy GFroce 3 TI 200 CD-RW DirectX 9.0 Beta 3 Sound Blaster Live! XP Pro, Registered PureBasic User Version 3.40 For Windows.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by qdriver.

Hi to all,
I do have exactly the same problem. But unfortunatly the purebasicbeginner page of Soultaker is not acessable.

Has anybody the file ListIconRow.Zip from this page and can help.

Thanks

Hans Georg
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

Code: Select all

Declare WndProc(hWnd, uMsg, wParam, lParam)

Global ListIconGadget
If OpenWindow(0, 100, 100, 295, 360, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")
  If CreateGadgetList(WindowID())
    ListIconGadget = ListIconGadget(0, 10, 10, 168, 250, "Fields", 164, #PB_ListIcon_CheckBoxes|#PB_ListIcon_FullRowSelect) 
    AddGadgetItem(0,-1,"Field1")
    AddGadgetItem(0,-1,"Field2")
    SetWindowCallback(@WndProc())
    Repeat
      EventID = WaitWindowEvent()
      Select EventID
        Case #PB_EventCloseWindow
          Quit = 1
        Case = #PB_EventGadget
          Select EventGadgetID()
            Case 0
              If EventType()=#PB_EventType_LeftClick    
                state = GetGadgetState(0)   
                state1 = GetGadgetItemState(0,0)
;                MessageRequester("Info","Row: " +Str(state) + " Item State: " + Str(state1),0)
              EndIf
          EndSelect
      EndSelect
    Until Quit
  EndIf
EndIf
End

Procedure WndProc(hWnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents
  Select uMsg
    Case #WM_NOTIFY
      *nmh.NMHDR = lParam
      If *nmh\hwndFrom=ListIconGadget
        Select *nmh\code
          Case #LVN_ITEMCHANGED
            *pnmv.NM_LISTVIEW = lParam
            If *pnmv\uChanged=8
              Select *pnmv\uNewState
                Case 8192
                  Debug "Item "+Str(*pnmv\iItem)+" checked"
                Case 4096
                  Debug "Item "+Str(*pnmv\iItem)+" unchecked"
              EndSelect
            EndIf
        EndSelect
      EndIf
  EndSelect
  ProcedureReturn result
EndProcedure
I hope this helps, bye,

El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by qdriver.

Hi El_Choni,

perfect many thanks...

Qdriver
Post Reply