TreeGadget: question about CheckBox and SelectedItem

Just starting out? Need help? Post your questions and find answers here.
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

TreeGadget: question about CheckBox and SelectedItem

Post by QuimV »

:)
Hi,
Here are a piece of code in order to ilustrate the question

Code: Select all

If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
    TreeGadget(0, 10, 10, 160, 160)                                         ; TreeGadget standard
    TreeGadget(1, 180, 10, 160, 160, #PB_Tree_CheckBoxes)  ; TreeGadget with Checkboxes + NoLines
    For ID = 0 To 1
      For a = 0 To 10
        AddGadgetItem (ID, -1, "Normal Item "+Str(a), 0, 0) ; if you want to add an image, use 
        AddGadgetItem (ID, -1, "Node "+Str(a), 0, 0)        ; ImageID(x) as 4th parameter
        AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1)    ; These are on the 1st sublevel  
        AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1)
        AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1)
        AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1)
        AddGadgetItem (ID, -1, "File "+Str(a), 0, 0) ; sublevel 0 again
      Next
    Next
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf
When I click in any Treecheckbox, this checkbox appears clicked but the selection remains in their current item (it doesn't change to the clicked node). Is normal this behavior?

When I click in a checkbox, How can I select the associated node item?

Thanks in advanced.
QuimV
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

For Windows:

Code: Select all

If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
    TreeGadget(0, 10, 10, 160, 160)                                         ; TreeGadget standard 
    TreeGadget(1, 180, 10, 160, 160, #PB_Tree_CheckBoxes)  ; TreeGadget with Checkboxes + NoLines 
    For ID = 0 To 1 
      For a = 0 To 10 
        AddGadgetItem (ID, -1, "Normal Item "+Str(a), 0, 0) ; if you want to add an image, use 
        AddGadgetItem (ID, -1, "Node "+Str(a), 0, 0)        ; ImageID(x) as 4th parameter 
        AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1)    ; These are on the 1st sublevel  
        AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1) 
        AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1) 
        AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1) 
        AddGadgetItem (ID, -1, "File "+Str(a), 0, 0) ; sublevel 0 again 
      Next 
    Next 
    Repeat
      ev=WaitWindowEvent()
      Select ev
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              If EventType()=#PB_EventType_LeftClick
                tvh.TV_HITTESTINFO
                GetCursorPos_(@tvh\pt)
                MapWindowPoints_(0, GadgetID(1), @tvh\pt, 1)
                SendMessage_(GadgetID(1), #TVM_HITTEST, 0, tvh)
                If tvh\flags&#TVHT_ONITEMSTATEICON	
                  tvi.TV_ITEM
                  tvi\mask = #TVIF_PARAM
                  tvi\hItem = tvh\hitem
                  SendMessage_(GadgetID(1), #TVM_GETITEM, 0, tvi)
                  item = tvi\lparam
                  SetGadgetState(1, item)
                EndIf
              EndIf        
          EndSelect      
      EndSelect
    Until ev = #PB_Event_CloseWindow 
  EndIf 
I may look like a mule, but I'm not a complete ass.
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Post by QuimV »

:D
hi srod,
It's just I need!
Thanks a lot
QuimV
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

You're welcome. :)
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Hi,

a slightly more efficient version:

Code: Select all

If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
    TreeGadget(0, 10, 10, 160, 160)                                         ; TreeGadget standard 
    TreeGadget(1, 180, 10, 160, 160, #PB_Tree_CheckBoxes)  ; TreeGadget with Checkboxes + NoLines 
    For ID = 0 To 1 
      For a = 0 To 10 
        AddGadgetItem (ID, -1, "Normal Item "+Str(a), 0, 0) ; if you want to add an image, use 
        AddGadgetItem (ID, -1, "Node "+Str(a), 0, 0)        ; ImageID(x) as 4th parameter 
        AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1)    ; These are on the 1st sublevel  
        AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1) 
        AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1) 
        AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1) 
        AddGadgetItem (ID, -1, "File "+Str(a), 0, 0) ; sublevel 0 again 
      Next 
    Next 
    Repeat
      ev=WaitWindowEvent()
      Select ev
        Case #PB_Event_Gadget
          Select EventGadget()
            Case 1
              If EventType()=#PB_EventType_LeftClick
                tvh.TV_HITTESTINFO
                GetCursorPos_(@tvh\pt)
                MapWindowPoints_(0, GadgetID(1), @tvh\pt, 1)
                SendMessage_(GadgetID(1), #TVM_HITTEST, 0, tvh)
                If tvh\flags&#TVHT_ONITEMSTATEICON	
                  SendMessage_(GadgetID(1), #TVM_SELECTITEM, #TVGN_CARET, tvh\hitem)
                EndIf
              EndIf        
          EndSelect      
      EndSelect
    Until ev = #PB_Event_CloseWindow 
  EndIf 
I may look like a mule, but I'm not a complete ass.
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Post by QuimV »

:D
Thanks again srod.

By the way. I'm trying to do some work when user check the TreeCheckBox. If the user use the mouse I detect the action with the event #PB_EventType_LeftClick, but if the user use the keyboard (arrows + spacebar) I can't find the way to detect the event with the EventType() function. In fact, I think the only way to detect this keyboard event is usig a WindowCallBack and detecting the #WM_LBUTTONDOWN message. Do you agree?

Thanks
QuimV
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

QuimV wrote:...In fact, I think the only way to detect this keyboard event is usig a WindowCallBack and detecting the #WM_LBUTTONDOWN message. Do you agree?
Nope! :)

Code: Select all

If OpenWindow(0, 0, 0, 355, 180, "TreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0)) 
    TreeGadget(0, 10, 10, 160, 160)                                         ; TreeGadget standard 
    TreeGadget(1, 180, 10, 160, 160, #PB_Tree_CheckBoxes)  ; TreeGadget with Checkboxes + NoLines 
    For ID = 0 To 1 
      For a = 0 To 10 
        AddGadgetItem (ID, -1, "Normal Item "+Str(a), 0, 0) ; if you want to add an image, use 
        AddGadgetItem (ID, -1, "Node "+Str(a), 0, 0)        ; ImageID(x) as 4th parameter 
        AddGadgetItem(ID, -1, "Sub-Item 1", 0, 1)    ; These are on the 1st sublevel  
        AddGadgetItem(ID, -1, "Sub-Item 2", 0, 1) 
        AddGadgetItem(ID, -1, "Sub-Item 3", 0, 1) 
        AddGadgetItem(ID, -1, "Sub-Item 4", 0, 1) 
        AddGadgetItem (ID, -1, "File "+Str(a), 0, 0) ; sublevel 0 again 
      Next 
    Next 
     Repeat 
      ev=WaitWindowEvent() 
      Select ev 
        Case #PB_Event_Gadget 
          Select EventGadget() 
            Case 1 
              If EventType()=#PB_EventType_LeftClick 
                tvh.TV_HITTESTINFO 
                GetCursorPos_(@tvh\pt) 
                MapWindowPoints_(0, GadgetID(1), @tvh\pt, 1) 
                SendMessage_(GadgetID(1), #TVM_HITTEST, 0, tvh) 
                If tvh\flags&#TVHT_ONITEMSTATEICON    
                  SendMessage_(GadgetID(1), #TVM_SELECTITEM, #TVGN_CARET, tvh\hitem) 
                  toggle=1
                EndIf 
              EndIf        
          EndSelect      
        Case #WM_KEYDOWN
          If EventGadget()=1 And EventwParam() = #VK_SPACE
            toggle=1
          EndIf
      EndSelect 
      If toggle
        toggle=0
        Debug "Checkbox toggled!"
      EndIf
    Until ev = #PB_Event_CloseWindow 
  EndIf 
I may look like a mule, but I'm not a complete ass.
QuimV
Enthusiast
Enthusiast
Posts: 337
Joined: Mon May 29, 2006 11:29 am
Location: BARCELONA - SPAIN

Post by QuimV »

:D
Chapeau, srod
And thanks for discover for me the EventwParam() function.
I didn't know it.
QuimV
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

QuimV wrote::D
Chapeau, srod
And thanks for discover for me the EventwParam() function.
I didn't know it.
I must admit that it's not something I feel comfortable with using. At one time I thought it had been deprecated, but oh well it's still here!
I may look like a mule, but I'm not a complete ass.
Post Reply