感谢大家非常快速和高质量的回复!
似乎没有内置的方法可以解决我的问题,我已经按照以下方式编写了代码(以防万一有人遇到类似问题):
// 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;