Delphi's operation (transfer, collection) for TreeView

xiaoxiao2021-03-06  61

How to initialize a TreeView?

Get a window, put a TreeView and a button, named TV1 and btn1, respectively.

If you need to have a picture in front of each node, put an imagelist on the window, name to ImageList1,

Double-click it, join six icons.

Also remember to change the image of the TV1 to ImageList1.

Double-click the button btn1, fill in the following code, then press F9 to run, click BTN1 to see the effect.

Procedure TFORM1.BTN1CLICK (Sender: TOBJECT);

Const mydocdir = 'c: / my documents';

Persondir = '3Hsoft';

VAR

VAR i: Word;

Subnodename: array [1..5] of shortstring;

Rootnode, Subnode: ttreenode;

P: pstring;

Begin

Subnodename [1]: = 'Notes';

Subnodename [2]: = 'outbox';

Subnodename [3]: = 'contact';

Subnodename [4]: ​​= 'Task';

Subnodename [5]: = 'diary';

TV1.Items.clear;

TV1.Items.beginupdate;

NEW (P);

P ^: = MYDOCDIR '/' PERSONDIR;

Rootnode: = tv1.items.addObject (NIL, 'Personal Folders', P);

// This Node icon has been taken 0 of the images attribute.

For i: = 1 to 5 do begin

NEW (P);

P ^: = MYDOCDIR '/' PERSONDIR '/' SUBNODENAME

Subnode: = tv1.items.addchildObject (rootnode, subnodename, p); // If you don't want to use the icon, please delete the following two lines of subnode.ImageIndex: = i; ende.selectedIndex: = i; end; TV1.Items. EndUpdate; End; II. How to set the node VAR i: integer; {i index value for the set node of the setting} begin if I> treeview1.items.count dam = true; Or TreeView1.Selected: = TreeView1.items; Third. Setting the TreeView Node 1. Setting the Image of TreeView for the existing images object TreeView1.images: = ImageList1; 2. Execute after joining the node: var Anode: Ttreenode; begein anode: = TreeView1.add (NIL, 'item1'); anode.imageindex: = 0; {Node is not selected icon} anode.selectedIndIndex: = 1; {Node selected icon} END 3. If the node graphics did not occur after the node graph Change, can be performed: TreeView1.refresh; IV. How to deal with TreeView nodes use TreeView's items attribute of BeginUpdate and EndUpdate method, example: TreeView1.items.beginupdate; for i: = 0 to TreeView1.Items.count-1 do begin // Each node is changed Become a lowercase letter TreeView1.Items.Text: = LowerCase (TreeView1.Items.text); end; treeview1.items.Endupdate; for i: = 1 to 5 do begin new (p); p ^: = mydocdir '/' PERSONDIR '/' SUBNODENAME

;

转载请注明原文地址:https://www.9cbs.com/read-84868.html

New Post(0)