VirtualStringTree columns should be sized when one column is hidden

I have a VST with 3 columns that evenly take up the available space.

(I set hoAutoSpring to Header.Options and all columns have column [x]. Option have set coAutoSpring.)

Now I want to hide the last column and claim that other columns uniformly take up free space (a bit like a control with alClient).

When I set the column invisible (see below), the space that was accepted by the column is simply not used.

VST.Header.Columns[2].Options:=VST.Header.Columns[2].Options - [coVisible]; 

When I set Header.Options.hoAutoResize to True and set Header.AutoSizeIndex to 1, then the second column will take up all the new space.

Is there a way to tell the columns to fill in the available space and evenly resize?

Screenshot:

enter image description here

+6
source share
1 answer

Thank you all for your very quick and high-quality answers!

It seems that there is no built-in way to solve my problem, I encoded it as follows (just in case someone encounters a similar problem):

 // Show/hide a column and spread the space on all other visible columns // so that the proportions remain the same (as if AutoSpring was used) procedure ChangeColumnVisibility(Tree: TVirtualStringTree; Column: TColumnIndex; NewVisible: boolean); var Col : TVirtualTreeColumn; begin Col:=Tree.Header.Columns[Column]; if not (NewVisible xor (coVisible in Col.Options)) then Exit; if not NewVisible then begin Col.Options:=Col.Options - [coVisible]; Tree.Header.ResizeColumns(Col.Width, 0, Tree.Header.Columns.Count-1); end else begin Tree.Header.ResizeColumns(-Col.Width, 0, Tree.Header.Columns.Count-1); Col.Options:=Col.Options + [coVisible]; end; end; procedure TForm1.Button1Click(Sender: TObject); begin ChangeColumnVisibility(VST, 2, not (coVisible in VST.Header.Columns[2].Options)); end; 
0
source

Source: https://habr.com/ru/post/958070/


All Articles