84079

How to display an icon or image in a column of TVirtualStringTree?

Question:

In a Delphi VCL project, I have created a simple TVirtualStringTree with two columns. The first column will contain text identifying the Name of the data being represented. The data record also contains a status field. The second column is intended to represent the status of the record using an image (16x16 pixel) w/o text.

I have searched demos, but have not mastered the full process for how VTV displays a node, and have not been successful in getting an icon to display in the node of a specified column.

So I have three related questions:

<ol><li>

I see how the text is assigned in the OnGetText event, but where should I assign or change the image to reflect the current status in my record?

</li> <li>

How do I get the image to actually display in the column?

</li> <li>

Am I limited in size for the images, or can they be larger than icons? If so, do I need to change any settings to adjust the height of each row (if possible)?

</li> </ol>

Answer1:

You need to assign (16x16 in your case) TImageList to the TVirtualStringTree.Images property, then handle the event OnGetImageIndex e.g.:

procedure TForm1.VirtualStringTree1GetImageIndex(Sender: TBaseVirtualTree; Node: PVirtualNode; Kind: TVTImageKind; Column: TColumnIndex; var Ghosted: Boolean; var ImageIndex: Integer); var NodeRec: PNodeRec; begin NodeRec := Sender.GetNodeData(Node); if Assigned(NodeRec) then begin if (Column = 1) then begin if Kind in [ikNormal, ikSelected] then begin case NodeRec.Status of // check the needed status(es) 1: ImageIndex := 1; // whichever image you need 2: ImageIndex := 2; // whichever image you need // ... end; end; end; end; end; <blockquote>

Am I limited in size for the images, or can they be larger than icons? If so, do I need to change any settings to adjust the height of each row (if possible)

</blockquote>

Not sure what you meant by that, because you stated you need a 16x16 images. You could use OnGetImageIndexEx if you need <em>different</em> image lists with possibly different dimensions. for variable height you could set toVariableNodeHeight in the TreeOptions.MiscOptionsand handle the OnMeasureItem event. another way to draw graphics into the VTV canvas is to handle the OnBeforeItemPaint/OnAfterItemPaint for example.

Answer2:

Create an image list 16x16 (Images) and use code like:

procedure TMyTreeView.OnDrawTextEx(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; const Text: string; const CellRect: TRect; var DefaultDraw: Boolean); var i: integer; begin if (Node <> nil) then begin case Column of cStatusColumn: begin DefaultDraw := false; i := 0; // assign the image index from Images list here if (i <> -1) then begin Images.Draw(TargetCanvas, CellRect.Left + ((CellRect.Width - Images.Width) div 2), CellRect.Top, i); end; end else begin DefaultDraw := true; end; end; end else begin DefaultDraw := true; end; end;

Recommend

  • Restarting nginx: nginxnginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
  • Java Vertical Layout?
  • Vue js bootstrap add animation while collapse
  • spring-boot restricted url
  • Start a JobIntentService Implicitly
  • iOS 11 on NavigationBar pull down - height of bar changes?
  • How to integrate application with excel macros?
  • Read Bluetooth RSSI on Windows 7/Vista/XP
  • opencv error: assertion failed (size.width>0 && size.height>0) in unknown function lin
  • How to set proxy settings for my application in .NET
  • Redirect www.mysite.com/index.html to www.mysite.com/ with .htaccess file
  • how to set datagridview column is left side of a datagridview
  • Resize C:\\ drive on Microsoft Azure Virtual Server
  • Inject Javascript code into a web page
  • Mapping google maps coordinate from a javascript variable
  • How to handle asynchronous error in Node.js
  • How do I set context and followup event in one intent?
  • Working with django : Proxy setup
  • CSV processing in Hadoop
  • Is there a way to run c# forms application without showing a gui window (like a console application)
  • Send HTML Mail with Unicode
  • how to get the size of the padding at the end of a class
  • Generate a runnable jar and include libraries in it with Maven
  • Filtering out choiceless polls in the Django tutorial causes polls in the index to duplicate
  • Convert current tmux session to configuration file
  • dmtracedump doesn't work, HELP!
  • Django REST framework - HyperlinkedRelatedField with additional parameter
  • separate tokens in batch file
  • Run a form (insert/update/delete) from within a div using jquery
  • LINQ to populate treeview based upon grouping
  • How to use Flask's render_template from an ajax POST form submit
  • How to run chrome.tabs.insertCSS from the background page on each page?
  • java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/SpringDispatcher-ser
  • Can I read another applications memory?
  • Google Spreadsheet Script to Blink a range of Cells
  • How to make 100% div height between header and footer?
  • Content-Type alternative in MQTT
  • Terminal run dalvikvm with am.jar
  • Angular FormGroup won't update it's value immediately after patchValue or setValue
  • ARKit code issue {unknown error -1=ffffffffffffffff error: Task failed with exit 1}