Page 1 of 2
ExplorerTreeGadget() and GetGadgetItemText()
Posted: Thu Jul 17, 2025 4:23 pm
by Jacobus
Hello,
I'm experiencing a return value issue with the GetGadgetItemText() function from an ExplorerTreeGadget(), and I'm wondering if this is a bug.
GetGadgetText() returns the full path of the selected item, while GetGadgetItemText() returns the root directory of a file, but a different root directory for a folder.
I find this very strange!???
A little test code to see the problem. Have I misinterpreted it?
(Test performed with PB 6.21 32-bit, Windows 11 Professional)
Code: Select all
If OpenWindow(0, 0, 0, 300, 300, "ExplorerTreeGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ExplorerTreeGadget(0, 10, 10, 280, 280, "")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_RightClick
SelectElement = GetGadgetState(0)
If SelectElement >= 0
If SelectElement & #PB_Explorer_File
Debug GetGadgetText(0)
Debug GetGadgetItemText(0, SelectElement, 0) ;<-- return C:\ ??
ElseIf SelectElement & #PB_Explorer_Directory
Debug GetGadgetText(0)
Debug GetGadgetItemText(0, SelectElement, 0) ;<-- return D:\ ??
EndIf
EndIf
EndSelect
EndSelect
EndIf
Until Event() = #PB_Event_CloseWindow
EndIf
Re: ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?
Posted: Thu Jul 17, 2025 4:58 pm
by Axolotl
I dont know, but I think that you cannot do this?
SelectElement is the position.
The Constants are not "compatible" with the position. I added a comment with what the compiler see.....
Code: Select all
; .....
If SelectElement & #PB_Explorer_File ; << SelectElement & $01
; .....
ElseIf SelectElement & #PB_Explorer_Directory ; << SelectElement & $02
; .....
You can use FileSize() to detect the File or Directory Type.
Re: ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?
Posted: Thu Jul 17, 2025 5:28 pm
by Jacobus
Hi Axoltl,
In my documentation ExplorerTreeGadget() is explained:
GetGadgetState() : Lets you know if the selected item is a directory or a file. <<
GetGadgetItemText() : Returns the full path of the specified item.
GetGadgetText() : Returns the full path of the selected directory or file.
This can be a big problem if you want to use GetGadgetItemText(#Gadget, Item [, Column]) to delete a file or directory. Thinking you got the full path to your file, you got a root directory.
It can be funny

Re: ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?
Posted: Thu Jul 17, 2025 6:07 pm
by Sirius-2337
Jacobus wrote: Thu Jul 17, 2025 5:28 pm
In my documentation ExplorerTreeGadget() is explained:
GetGadgetState() : Lets you know if the selected item is a directory or a file. <<
That is correct, but you are using the return value as 'position' for GetGadgetItemText.
It's not returning an index, just the
type of the selected item.
Re: ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?
Posted: Thu Jul 17, 2025 6:48 pm
by Little John
Jacobus wrote: Thu Jul 17, 2025 5:28 pm
ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?
I wonder whether it is possible to ask a simple coding question without using the word “bug”.

Re: ExplorerTreeGadget() and GetGadgetItemText()
Posted: Thu Jul 17, 2025 6:59 pm
by Jacobus
Little John wrote: Thu Jul 17, 2025 6:48 pm
Jacobus wrote: Thu Jul 17, 2025 5:28 pm
ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?
I wonder whether it is possible to ask a simple coding question without using the word “bug”.
bug was removed from the title.
Re: ExplorerTreeGadget() and GetGadgetItemText() >> is this a bug?
Posted: Thu Jul 17, 2025 7:04 pm
by Jacobus
Sirius-2337 wrote: Thu Jul 17, 2025 6:07 pm
Jacobus wrote: Thu Jul 17, 2025 5:28 pm
In my documentation ExplorerTreeGadget() is explained:
GetGadgetState() : Lets you know if the selected item is a directory or a file. <<
That is correct, but you are using the return value as 'position' for GetGadgetItemText.
It's not returning an index, just the
type of the selected item.
Ok, but in these conditions how do you get the position of the element in question?
Re: ExplorerTreeGadget() and GetGadgetItemText()
Posted: Fri Jul 18, 2025 11:03 am
by Axolotl
Okay, I read you code and not the help for that command.
You are right. The GetGadgetState() is different for this Gadget.
HELP-Text:
The following functions can be used to control the gadget:
- GetGadgetText(): Get the full path of the currently selected directory/file.
- SetGadgetText(): Set the currently selected file/directory.
- GetGadgetState(): Check if the selected item is a file or a directory.
- GetGadgetItemText(): Returns the full path of the specified item.
So there seems to be no PB way to identify the selected element. Which would be needed for the parameter Position in the GetGadgetItemText()
Furthermore,
GetGadgetItemText() would only return the same result as
GetGadgetText().
From my point of view, the help should probably be corrected by removing the forth function.
Re: ExplorerTreeGadget() and GetGadgetItemText()
Posted: Fri Jul 18, 2025 2:01 pm
by Jacobus
Axolotl wrote: Fri Jul 18, 2025 11:03 am
So there seems to be no PB way to identify the selected element. Which would be needed for the parameter Position in the GetGadgetItemText()
Furthermore,
GetGadgetItemText() would only return the same result as
GetGadgetText().
From my point of view, the help should probably be corrected by removing the forth function.
I came to the same conclusion. That was also why I wanted to test both functions and see the difference in the results. But the function is incomplete if we can't have the position argument.
Re: ExplorerTreeGadget() and GetGadgetItemText()
Posted: Fri Jul 18, 2025 5:26 pm
by HeX0R
I'd say GetGadgetState() should work like for all the other gadgets and return the selected index.
It feels strange, when it here returns the kind of selection.
Anyway, no bug, more a feature request.
Unfortunately it would break existing codes.
Not mine though, I never use ExplorerTreeGadgets

Re: ExplorerTreeGadget() and GetGadgetItemText()
Posted: Fri Jul 18, 2025 6:12 pm
by mk-soft
HeX0R wrote: Fri Jul 18, 2025 5:26 pm
I'd say GetGadgetState() should work like for all the other gadgets and return the selected index.
It feels strange, when it here returns the kind of selection.
Anyway, no bug, more a feature request.
Unfortunately it would break existing codes.
Not mine though, I never use ExplorerTreeGadgets
See GetGadgetState Help. Is not always the index ...
Depending on the gadget type, it is different.
Re: ExplorerTreeGadget() and GetGadgetItemText()
Posted: Fri Jul 18, 2025 8:39 pm
by HeX0R
I was talking about those Gadgets which allow more entries.
Here I see exactly one, where things are different.
Especially if you compare ExplorerList and ExplorerTree gadget.
Re: ExplorerTreeGadget() and GetGadgetItemText()
Posted: Fri Jul 18, 2025 11:20 pm
by Jacobus
HeX0R wrote: Fri Jul 18, 2025 8:39 pm
I was talking about those Gadgets which allow more entries.
Here I see exactly one, where things are different.
Especially if you compare ExplorerList and ExplorerTree gadget.
This is exactly what is confusing. Especially since GetGadgetState() in ExplorerTreeGadget() must obtain the index of the selection to be able to tell if it is a file or a folder. At least, it seems so to me. In this case, it would indeed be desirable for a function to be able to return the index of a file in an ExplorerTreeGadget() to fully exploit it, without torturing oneself to write a routine that gives the index.

Re: ExplorerTreeGadget() and GetGadgetItemText()
Posted: Fri Jul 18, 2025 11:57 pm
by mk-soft
The index changes every time a tree is opened or closed.
Thus, the index does not help.
Re: ExplorerTreeGadget() and GetGadgetItemText()
Posted: Sat Jul 19, 2025 2:11 am
by BarryG
mk-soft wrote: Fri Jul 18, 2025 11:57 pmThe index changes every time a tree is opened or closed.
But if you run the code from the first post and DON'T open anything, and just simply right-click "C:\" and don't do anything else, the debug output shows both "C:\" and "D:\" for that selected item. (Assuming you have a D: drive, like I do).
