![]() |
AW: TVirtualStringTree AutoFitColumns erste Spalte wird nicht angepasst
Zitat:
Mache bei den MiscOptions mal toGridExtensions rein, dann sollte es funzen. |
AW: TVirtualStringTree AutoFitColumns erste Spalte wird nicht angepasst
Zitat:
Und das habe ich ja die ganze Zeit auch gemeint da das Verhalten so merkwürdig ist das ich da auch auf einen Bug schließe und nicht auf ein gewolltes Verhalten. Ich hatte das auch so als Bug Report bei GitHub eingestellt. |
AW: TVirtualStringTree AutoFitColumns erste Spalte wird nicht angepasst
Zitat:
|
AW: TVirtualStringTree AutoFitColumns erste Spalte wird nicht angepasst
Bitte sehr. Option toGridExtensions hinzugefügt und die "^" eingebaut. Mehr nicht. Läuft, falls man einen Node selektiert hat. ;)
Delphi-Quellcode:
object Form2: TForm2
Left = 0 Top = 0 Caption = 'Form2' ClientHeight = 489 ClientWidth = 730 Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object vstTable: TVirtualStringTree Left = 112 Top = 88 Width = 505 Height = 345 Header.AutoSizeIndex = 0 Header.Font.Charset = DEFAULT_CHARSET Header.Font.Color = clWindowText Header.Font.Height = -11 Header.Font.Name = 'Tahoma' Header.Font.Style = [] Header.Options = [hoColumnResize, hoDrag, hoShowSortGlyphs, hoVisible] TabOrder = 0 TreeOptions.MiscOptions = [toAcceptOLEDrop, toFullRepaintOnResize, toGridExtensions, toInitOnSave, toToggleOnDblClick, toWheelPanning, toEditOnClick] TreeOptions.PaintOptions = [toHideFocusRect, toShowButtons, toShowDropmark, toShowTreeLines, toThemeAware, toUseBlendedImages] TreeOptions.SelectionOptions = [toFullRowSelect] OnGetText = vstTableGetText Columns = < item Position = 0 WideText = 'Name' end item Position = 1 WideText = 'Description' end> end object Button1: TButton Left = 144 Top = 57 Width = 75 Height = 25 Caption = 'Button1' TabOrder = 1 OnClick = Button1Click end end
Delphi-Quellcode:
unit Unit2;
interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, VirtualTrees, Vcl.StdCtrls; type TMyDataSet = record Name: String; Desc: String; end; PMyDataSet = ^TMyDataSet; type TForm2 = class(TForm) vstTable: TVirtualStringTree; Button1: TButton; procedure FormCreate(Sender: TObject); procedure vstTableGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string); procedure Button1Click(Sender: TObject); private { Private-Deklarationen } public { Public-Deklarationen } end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); var Node: PVirtualNode; Data: PMyDataSet; begin vstTable.BeginUpdate; Node := vstTable.FocusedNode; if Assigned(Node) then begin Data := vstTable.GetNodeData(Node); if Assigned(Data) then begin Data^.Name := Data^.Name + 'xyz 12345'; Data^.Desc := Data^.Desc + 'xyz 12345'; end; end; vstTable.EndUpdate; vstTable.Header.AutoFitColumns(False, smaAllColumns); end; procedure TForm2.FormCreate(Sender: TObject); var Node: PVirtualNode; Data: PMyDataSet; Index: Integer; begin vstTable.NodeDataSize := SizeOf(TMyDataSet); vstTable.BeginUpdate; for Index := 1 to 10 do begin Node := vstTable.AddChild(nil); Data := vstTable.GetNodeData(Node); if Assigned(Data) then begin Data^.Name := IntToStr(Index)+'. Bla bla'; Data^.Desc := 'Bla bla bla bla'; end; end; vstTable.EndUpdate; vstTable.Header.AutoFitColumns(False, smaAllColumns); end; procedure TForm2.vstTableGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string); var Data: PMyDataSet; begin Data := vstTable.GetNodeData(Node); if Assigned(Data) then begin case Column of 0: CellText := Data^.Name; 1: CellText := Data^.Desc; end; end; end; end. |
AW: TVirtualStringTree AutoFitColumns erste Spalte wird nicht angepasst
Zitat:
Ich denke aber ich bin des Rätsels Lösung schon sehr sehr nahe. In TCustomVirtualStringTree.DoGetNodeWidth:
Delphi-Quellcode:
Der Schweinehund puffert doch die Textbreite tatsächlich! Wahrscheinlich aus Performancegründen, um eben nicht für jede einzelne Zelle die Textbreite über den DeviceContext berechnen zu müssen. Und hier kommt auch die Erklärung, warum es mit einem InvalidateNode funktioniert:
if Column = FHeader.MainColumn then
begin // Primary column or no columns. Data := InternalData(Node); // <-- Magic Wunderding !!! if Assigned(Data) then begin Result := Data^; if Result = 0 then begin Data^ := CalculateTextWidth(Canvas, Node, Column, Text[Node, Column]); Result := Data^; end; end else Result := 0; end
Delphi-Quellcode:
So: Rätsel gelöst! Ich lag falsch, der VST puffert doch die Textbreite. Daher ist die einzig richtige Lösung, ein InvalidateNode zu machen.
function TCustomVirtualStringTree.InvalidateNode(Node: PVirtualNode): TRect;
var Data: PInteger; begin Result := inherited InvalidateNode(Node); // Achtung !!! Hier des Rätsels Lösung: // Reset node width so changed text attributes are applied correctly. if Assigned(Node) then begin Data := InternalData(Node); if Assigned(Data) then Data^ := 0; // !!! InternalData wird auf 0 gesetzt, weshalb GetNodeWidth dann gezwungen ist neu zu berechnen. // Reset height measured flag too to cause a re-issue of the OnMeasureItem event. Exclude(Node.States, vsHeightMeasured); end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:15 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz