bei Doppelklick zwischen zwei Spalten (vst liegt als Komponente in einem Frame):
Delphi-Quellcode:
vst: TVirtualStringTree;
FmerkOnBeforeCellPaint: TVTBeforeCellPaintEvent;
procedure TFrameVST.vstBeforeGetMaxColumnWidth(Sender: TVTHeader; Column: TColumnIndex; var UseSmartColumnWidth: Boolean);
begin
if Assigned(vst.OnBeforeCellPaint) then
begin
FmerkOnBeforeCellPaint := vst.OnBeforeCellPaint;
vst.OnBeforeCellPaint := nil;
end;
end;
procedure TFrameVST.vstAfterGetMaxColumnWidth(Sender: TVTHeader; Column: TColumnIndex; var MaxWidth: Integer);
begin
if Assigned(FmerkOnBeforeCellPaint) then
begin
vst.OnBeforeCellPaint := FmerkOnBeforeCellPaint;
FmerkOnBeforeCellPaint := nil;
end;
end;
procedure TFrameVST.vstColumnWidthDblClickResize(Sender: TVTHeader; Column: TColumnIndex; Shift: TShiftState; P: TPoint;
var Allowed: Boolean);
begin
if (Allowed) and (Shift = []) then
begin
AutoFitColumn(Column);
Allowed := False;
end;
end;
procedure TFrameVST.AutoFitColumn(Column: TColumnIndex);
var
cWidth, hWidth: Integer;
begin
if [coResizable, coVisible] * vst.Header.Columns[Column].Options = [coResizable, coVisible] then
begin
cWidth := vst.GetMaxColumnWidth(Column);
if (hoVisible in vst.Header.Options) then
begin
hWidth := GetMaxHeaderWidth(Column);
if cWidth < hWidth then
cWidth := hWidth;
if cWidth > vst.Header.Columns[Column].MaxWidth then
cWidth := vst.Header.Columns[Column].MaxWidth;
end;
vst.Header.Columns[Column].Width := cWidth;
end;
end;