ral*_*iii 6 delphi virtualtreeview tvirtualstringtree
我有一个3列的VST,可以均匀占用可用空间.
(我在Header.Options中设置了hoAutoSpring,所有列都有Column [x] .Option设置了coAutoSpring.)
现在我希望能够隐藏最后一列并保持其他列均匀占用空闲空间(有点像alClient控件).
当我只将列设置为不可见(见下文)时,该列占用的空间就不再使用了.
VST.Header.Columns[2].Options:=VST.Header.Columns[2].Options - [coVisible];
Run Code Online (Sandbox Code Playgroud)
当我将Header.Options.hoAutoResize设置为True并将Header.AutoSizeIndex设置为1时,第二列将占用所有新空间.
是否有方法告诉列填充可用空间并均匀调整大小?
截图:
感谢大家非常快速和高质量的回复!
因为似乎没有内置的方法来解决我的问题,所以我按以下方式编码(以防万一有人遇到类似的问题):
// 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;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1502 次 |
最近记录: |