TreeGadget() no visible selection

Post bugreports for the Windows version here
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

TreeGadget() no visible selection

Post by HeX0R »

Run this code and press the button to see the effect.

Code: Select all

OpenWindow(0, 0, 0, 300, 300, "", #PB_Window_SystemMenu)
TreeGadget(0, 5, 5, 290, 260)
ButtonGadget(1, 25, 270, 120, 24, "Add Item")

AddGadgetItem(0, -1, "Item 1", 0, 0)
AddGadgetItem(0, -1, "Item 2", 0, 0)
AddGadgetItem(0, -1, "Item 3", 0, 1)
AddGadgetItem(0, -1, "Item 4", 0, 1)

SetGadgetItemState(0, 1, #PB_Tree_Expanded)

Repeat
	Select WaitWindowEvent()
		Case #PB_Event_CloseWindow
			Break
		Case #PB_Event_Gadget
			Select EventGadget()
				Case 1
					AddGadgetItem(0, 1, "Added #1", 0, 0)
					AddGadgetItem(0, 2, "Added #2", 0, 1)
					AddGadgetItem(0, 3, "Added #3", 0, 1)
					SetGadgetState(0, 1)
					SetGadgetItemState(0, 1, #PB_Tree_Expanded)
					If GetGadgetState(0) = 1
						Debug "Added #1 is selected, but you don't see it!"
						Debug "Try to select Added #1 with the mouse, you will not see anything"
					EndIf
			EndSelect
	EndSelect
ForEver
User avatar
Bisonte
Addict
Addict
Posts: 1226
Joined: Tue Oct 09, 2007 2:15 am

Re: TreeGadget() no visible selection

Post by Bisonte »

Confirmed on Win 10 x64 with PB 5.62 (x86/x64)
PureBasic 6.04 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Demivec
Addict
Addict
Posts: 4085
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: TreeGadget() no visible selection

Post by Demivec »

I don't think it's a bug, though I can't rule that out.

I think the more proper code may be to write it this way (note the two changed and commented lines in 'Case 1'):

Code: Select all

OpenWindow(0, 0, 0, 300, 300, "", #PB_Window_SystemMenu)
TreeGadget(0, 5, 5, 290, 260)
ButtonGadget(1, 25, 270, 120, 24, "Add Item")

AddGadgetItem(0, -1, "Item 1", 0, 0)
AddGadgetItem(0, -1, "Item 2", 0, 0)
AddGadgetItem(0, -1, "Item 3", 0, 1)
AddGadgetItem(0, -1, "Item 4", 0, 1)

SetGadgetItemState(0, 1, #PB_Tree_Expanded)

Repeat
   Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
         Break
      Case #PB_Event_Gadget
         Select EventGadget()
            Case 1
               AddGadgetItem(0, 1, "Added #1", 0, 0)
               AddGadgetItem(0, 2, "Added #2", 0, 1)
               AddGadgetItem(0, 3, "Added #3", 0, 1)
               SetGadgetState(0, 1)
               SetGadgetItemState(0, 1, #PB_Tree_Selected | #PB_Tree_Expanded) ;Formally select the item
               SetActiveGadget(0) ;and make the gadget active to show the selection
               If GetGadgetState(0) = 1
                  Debug "Added #1 is selected, but you don't see it!"
                  Debug "Try to select Added #1 with the mouse, you will not see anything"
               EndIf
         EndSelect
   EndSelect
ForEver
User avatar
HeX0R
Addict
Addict
Posts: 980
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: TreeGadget() no visible selection

Post by HeX0R »

Maybe it's the more proper way, anyway I would say it shouldn't happen at all, that you click on a tree item and it will not be (visual) selected, don't you think?
User avatar
mk-soft
Always Here
Always Here
Posts: 5334
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: TreeGadget() no visible selection

Post by mk-soft »

I think it's a problem with the order the commands go to control.
Besides that a flag is missing

Code: Select all

OpenWindow(0, 0, 0, 300, 300, "", #PB_Window_SystemMenu)
TreeGadget(0, 5, 5, 290, 260, #PB_Tree_AlwaysShowSelection)
ButtonGadget(1, 25, 270, 120, 24, "Add Item")

AddGadgetItem(0, -1, "Item 1", 0, 0)
AddGadgetItem(0, -1, "Item 2", 0, 0)
AddGadgetItem(0, -1, "Item 3", 0, 1)
AddGadgetItem(0, -1, "Item 4", 0, 1)

SetGadgetItemState(0, 1, #PB_Tree_Expanded)

;SetWindowTheme_(GadgetID(0), @"Explorer", 0)
    
Repeat
   Select WaitWindowEvent()
      Case #PB_Event_CloseWindow
         Break
      Case #PB_Event_Gadget
         Select EventGadget()
            Case 1
               AddGadgetItem(0, 1, "Added #1", 0, 0)
               AddGadgetItem(0, 2, "Added #2", 0, 1)
               AddGadgetItem(0, 3, "Added #3", 0, 1)
               SetGadgetItemState(0, 1, #PB_Tree_Expanded)
               SetGadgetState(0, 1)
               If GetGadgetState(0) = 1
                  Debug "Added #1 is selected, but you don't see it!"
                  Debug "Try to select Added #1 with the mouse, you will not see anything"
               EndIf
         EndSelect
   EndSelect
ForEver
So works with Window 7 and 10

P.S. Same on Linux and Mac
Works only if first expanded tree, then set item
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply