[fpc-pascal] Directory Tree

Jean SUZINEAU jean.suzineau at wanadoo.fr
Thu Apr 8 12:55:32 CEST 2021


If you just select files, as Bart stated in another message, I think 
TShellTreeView will be more adequate and easier than TTreeView (actually 
TShellTreeView is a file tree specific descendent TTreeView).

In TTreeView (and TShellTreeView) you can enable multiselection by 
adding tvoAllowMultiSelect in Options set (something like "with 
TreeView1 do Options:=Options+[tvoAllowMultiSelect];"   or better by 
just checking Options/tvoAllowMultiSelect in the Object inspector)

https://wiki.freepascal.org/TTreeView#Example_of_using_Multiple_Node_Selection_for_Multiple_User_Selections

If you want checkboxes, I think it's possible with TVirtualStringTree 
from the VirtualTreeView package, it may be a bit harder to implement 
(as far as  I remember you need your own data structure to store the 
status of the tree) :

https://wiki.freepascal.org/VirtualTreeview

https://wiki.freepascal.org/VirtualTreeview_Example_for_Lazarus#Checkbox

VirtualTreeView package is included in Lazarus v2.0+, but I'm not sure 
it's installed by default: if you don't find a tab "Virtual controls" in 
your components, you may need to go to Package menu/Install packages, 
select virtualtreeview_package 5.5.3.1 for installation and rebuild 
Lazarus.

Here you should enable multiselection with something like

with VirtualStringTree1.TreeOptions do 
SelectionOptions:=SelectionOptions+[toMultiSelect];

or by checking TreeOptions/SelectionOptions/toMultiSelect in the Object 
inspector when your VirtualStringTree1 is selected.

(I've used VirtualTreeView a while ago, I didn't test checkboxes today)



More information about the fpc-pascal mailing list