How to hide checkboxes in a TreeGadget?

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

How to hide checkboxes in a TreeGadget?

Post by AZJIO »

Code: Select all

toggle = 1
If OpenWindow(0, 0, 0, 420, 800, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TreeGadget(0, 10, 40, 400, 700, 0)
	For a = 0 To 3
		AddGadgetItem(0, -1, "normal "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "node  "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "Sub- 1", 0, 1)
		AddGadgetItem(0, -1, "Sub- 2", 0, 1)
		AddGadgetItem(0, -1, "Sub- 3", 0, 1)
		AddGadgetItem(0, -1, "Sub- 4", 0, 1)
		AddGadgetItem(0, -1, "File "+Str(a), 0, 0)
	Next
	ButtonGadget(1, 11, 11, 26, 26, "+")
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1
						toggle = Bool(Not toggle)
						If toggle
; 							how to hide checkboxes
							SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) &~ #PB_Tree_CheckBoxes)
						Else
							SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) | #PB_Tree_CheckBoxes)
						EndIf
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to hide checkboxes in a TreeGadget?

Post by jacdelad »

Hi AZJIO,
this ist not possible (look at TVS_CHECKBOXES):

Code: Select all

https://learn.microsoft.com/en-us/windows/win32/controls/tree-view-control-window-styles
Version 5.80. Displays a check box even if no image is associated with the item.
Once a tree-view control is created with this style, the style cannot be removed.
...so this works only on rather old Windows versions.

BTW, you shouldn't use PureBasic constant for API calls, use the Windows constant instead. It worked this time, but this not always the case.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
BarryG
Addict
Addict
Posts: 4219
Joined: Thu Apr 18, 2019 8:17 am

Re: How to hide checkboxes in a TreeGadget?

Post by BarryG »

jacdelad wrote: Mon Jul 08, 2024 8:25 amthis ist not possible
What about this StackOverflow code -> https://stackoverflow.com/a/34320003/7908170
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 487
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: How to hide checkboxes in a TreeGadget?

Post by Mindphazer »

Hi,
in one of my applications, i display a treegadget and the user can choose to display checkboxes or not.
The only way i found is to free and redraw the treegadget with or without the #PB_Tree_CheckBoxes option.

If there's an easier way to do that, i'd be glad to know it :P
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to hide checkboxes in a TreeGadget?

Post by jacdelad »

BarryG wrote: Mon Jul 08, 2024 9:08 am
jacdelad wrote: Mon Jul 08, 2024 8:25 amthis ist not possible
What about this StackOverflow code -> https://stackoverflow.com/a/34320003/7908170
Microsoft themselves said it is not possible (anymore). The quaestion on stack overflow was asked 8 years ago, so maybe they tested it on Windows<Vista. However, I have Nightshift this week and my company is still idling, so I surely will have time to translate it to PureBasic test it (if nobody is doing it before). But I'm sure this won't work.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: How to hide checkboxes in a TreeGadget?

Post by AZJIO »

after cancellation, it is impossible to check the box, it does not visually disappear
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: How to hide checkboxes in a TreeGadget?

Post by RASHAD »

One step forward

Code: Select all

toggle = 1
If OpenWindow(0, 0, 0, 420, 800, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TreeGadget(0, 10, 40, 400, 700,#PB_Tree_CheckBoxes)
	imglist = SendMessage_(GadgetID(0),#TVM_GETIMAGELIST,#TVSIL_STATE,0)

	For a = 0 To 3
		AddGadgetItem(0, -1, "normal "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "node  "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "Sub- 1", 0, 1)
		AddGadgetItem(0, -1, "Sub- 2", 0, 1)
		AddGadgetItem(0, -1, "Sub- 3", 0, 1)
		AddGadgetItem(0, -1, "Sub- 4", 0, 1)
		AddGadgetItem(0, -1, "File "+Str(a), 0, 0)
	Next

	ButtonGadget(1, 11, 11, 26, 26, "+")
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1
						toggle = Bool(Not toggle)
						If toggle	
               ImageList_SetIconSize_(imglist,16,16)
               SendMessage_(GadgetID(0),#TVM_SETIMAGELIST,#TVSIL_STATE,imglist)					
							SendMessage_(GadgetID(0),#WM_SETREDRAW,1,0)
					  Else
							  ImageList_SetIconSize_(imglist,0,16)
                SendMessage_(GadgetID(0),#TVM_SETIMAGELIST,#TVSIL_STATE,imglist)					
							  SendMessage_(GadgetID(0),#WM_SETREDRAW,1,0)
						EndIf
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf
Egypt my love
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to hide checkboxes in a TreeGadget?

Post by jacdelad »

RASHAD-GPTs idea is not bad. Combining it with the original code seems to work:

Code: Select all

toggle = 1
If OpenWindow(0, 0, 0, 420, 800, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TreeGadget(0, 10, 40, 400, 700, 0)
	imglist = SendMessage_(GadgetID(0),#TVM_GETIMAGELIST,#TVSIL_STATE,0)
	For a = 0 To 3
		AddGadgetItem(0, -1, "normal "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "node  "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "Sub- 1", 0, 1)
		AddGadgetItem(0, -1, "Sub- 2", 0, 1)
		AddGadgetItem(0, -1, "Sub- 3", 0, 1)
		AddGadgetItem(0, -1, "Sub- 4", 0, 1)
		AddGadgetItem(0, -1, "File "+Str(a), 0, 0)
	Next
	ButtonGadget(1, 11, 11, 26, 26, "+")
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1
						toggle = Bool(Not toggle)
						If toggle
; 							how to hide checkboxes
							SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) &~ #PB_Tree_CheckBoxes)
							  ImageList_SetIconSize_(imglist,0,16)
                SendMessage_(GadgetID(0),#TVM_SETIMAGELIST,#TVSIL_STATE,imglist)					
							  SendMessage_(GadgetID(0),#WM_SETREDRAW,1,0)
						Else
							SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) | #PB_Tree_CheckBoxes)
						EndIf
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf
Though I don't know whether real icons will be usable...
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: How to hide checkboxes in a TreeGadget?

Post by RASHAD »

1st step RASHAD
2nd step jacdelad
3rd step RASHAD
4th step ????????

Code: Select all

toggle = 1
If OpenWindow(0, 0, 0, 420, 800, "Example...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
	TreeGadget(0, 10, 40, 400, 700, #PB_Tree_CheckBoxes)
	imglist = SendMessage_(GadgetID(0),#TVM_GETIMAGELIST,#TVSIL_STATE,0)
	For a = 0 To 3
		AddGadgetItem(0, -1, "normal "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "node  "+Str(a), 0, 0)
		AddGadgetItem(0, -1, "Sub- 1", 0, 1)
		AddGadgetItem(0, -1, "Sub- 2", 0, 1)
		AddGadgetItem(0, -1, "Sub- 3", 0, 1)
		AddGadgetItem(0, -1, "Sub- 4", 0, 1)
		AddGadgetItem(0, -1, "File "+Str(a), 0, 0)
	Next
	ButtonGadget(1, 11, 11, 26, 26, "+")
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_Gadget
				Select EventGadget()
					Case 1
						toggle = Bool(Not toggle)
						If toggle
              SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) | #PB_Tree_CheckBoxes)
              SendMessage_(GadgetID(0),#TVM_SETIMAGELIST,#TVSIL_STATE,imglist)
						Else
						  SetWindowLongPtr_(GadgetID(0), #GWL_STYLE, GetWindowLongPtr_(GadgetID(0), #GWL_STYLE) &~ #PB_Tree_CheckBoxes)
						  SendMessage_(GadgetID(0),#TVM_SETIMAGELIST,#TVSIL_STATE,0)							
						EndIf
				EndSelect
			Case #PB_Event_CloseWindow
				CloseWindow(0)
				End
		EndSelect
	ForEver
EndIf
Egypt my love
AZJIO
Addict
Addict
Posts: 2225
Joined: Sun May 14, 2017 1:48 am

Re: How to hide checkboxes in a TreeGadget?

Post by AZJIO »

Thanks, I used this in my program (FileSizesList)
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: How to hide checkboxes in a TreeGadget?

Post by jacdelad »

BTW, I'm impressed that something, of which the Windows SDK tells us it is not possible, is possible with such a little trick. :mrgreen:
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply