[SOLVED] Cannot select explorer item

Just starting out? Need help? Post your questions and find answers here.
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

[SOLVED] Cannot select explorer item

Post by SkyManager »

I cannot figure out why I cannot select the explorer item.
Could anybody help?

Code: Select all

If Not OpenWindow(0, 100, 100, 500, 300, "Test", #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_SystemMenu)
  End
EndIf
ExplorerListGadget(1, 0, 0, 200, 200, "", #PB_Explorer_AlwaysShowSelection | #PB_Explorer_FullRowSelect | #PB_Explorer_AutoSort | #PB_Explorer_MultiSelect)
SetGadgetItemState(1, 1, #PB_ListIcon_Selected) ; <-- PROBLEM
While #True
	Event = WaitWindowEvent()
	If Event = #PB_Event_CloseWindow
		End
	EndIf
Wend
Last edited by SkyManager on Sat Apr 04, 2015 6:14 am, edited 1 time in total.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Cannot select explorer item

Post by Danilo »

Use #PB_Explorer_Selected - it's a mistake in the documentation for SetGadgetItemState().

Code: Select all

If Not OpenWindow(0, 100, 100, 500, 300, "Test", #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget | #PB_Window_SizeGadget | #PB_Window_SystemMenu)
  End
EndIf
ExplorerListGadget(1, 0, 0, 400, 200, "", #PB_Explorer_AlwaysShowSelection | #PB_Explorer_FullRowSelect | #PB_Explorer_AutoSort | #PB_Explorer_MultiSelect)
SetGadgetItemState(1, 1, #PB_Explorer_Selected) ; <-- PROBLEM solved
SetActiveGadget(1)
While #True
   Event = WaitWindowEvent()
   If Event = #PB_Event_CloseWindow
      End
   EndIf
Wend
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Re: Cannot select explorer item

Post by SkyManager »

Thanks a lot,
a follow-up question.
How to DE-select an item?
The documentaion only tells us how to select an item.
User avatar
Danilo
Addict
Addict
Posts: 3036
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

Re: Cannot select explorer item

Post by Danilo »

Undocumented, but seems to work (on Windows):

Code: Select all

#PB_Explorer_Deselected = 0

SetGadgetItemState(1, 1, #PB_Explorer_Selected)    ; Select
SetGadgetItemState(1, 1, #PB_Explorer_Deselected)  ; De-Select

SetGadgetItemState(1, -1, #PB_Explorer_Selected)   ; Select All
SetGadgetItemState(1, -1, #PB_Explorer_Deselected) ; Clear Selection
User avatar
Shardik
Addict
Addict
Posts: 2058
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Cannot select explorer item

Post by Shardik »

Danilo wrote:Undocumented, but seems to work (on Windows):
That's right, it's only documented for the ListViewGadget but it seems indeed to work cross-platform for the ExplorerListGadget. The following example code was successfully tested on
- MacOS X 10.6.8 (Snow Leopard)
- Ubuntu 14.04 x64 with KDE
- Windows 7 x64 SP1

Code: Select all

OpenWindow(0, 100, 100, 420, 310, "Test")
ButtonGadget(0, 150, 280, 120, 25, "Unselect row 1")
ExplorerListGadget(1, 10, 10, 400, 260, "/",
  #PB_Explorer_FullRowSelect | #PB_Explorer_MultiSelect)
SetGadgetItemState(1, 1, #PB_Explorer_Selected)
SetActiveGadget(1)

Repeat
   Select WaitWindowEvent()
     Case #PB_Event_CloseWindow
       Break
     Case #PB_Event_Gadget
       If EventGadget() = 0
         SetGadgetItemState(1, 1, 0)
       EndIf
   EndSelect
ForEver
SkyManager
Enthusiast
Enthusiast
Posts: 339
Joined: Tue Jan 30, 2007 5:47 am
Location: Hong Kong

Re: Cannot select explorer item

Post by SkyManager »

Thanks for the answer

My little experiment is as follow :

Code: Select all

state = GetGadgetItemState(#DirExplorer, k)
    If state & #PB_Explorer_File 
       SetGadgetItemState(#DirExplorer, k, #PB_Explorer_File)
    ElseIf state & #PB_Explorer_Directory
       SetGadgetItemState(#DirExplorer, k, #PB_Explorer_Directory)
    EndIf
That seems to work also
Post Reply