Learn ttreeview [14]-stateindex (status icon) and overlayindex (overlay icon)

Source: Internet
Author: User
Add the following icon to imagelist1:


Tips about overlayindex:
Before specifying an overlayindex for a node, use imagelist1.overlay to specify the available overlayindex number.

Test:


Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, modules, imglist, stdctrls, extctrls; Type tform1 = Class (tform) treeview1: metadata; identifier: timagelist; edit1: tedit; edit2: tedit; label1: tlabel; label2: tlabel; button1: tbutton; Procedure formcreate (Sender: tobject); Procedure edit1keyup: tobject; var key: word; shift: tshiftstate); Procedure edit2keyup (Sender: tobject; var key: word; shift: tshiftstate); Procedure treeview1change (Sender: tobject; node: ttreenode); Procedure button1click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} procedure tform1.formcreate (Sender: tobject); var node: ttreenode; begin {specify imagelist} treeview1.images: = imagelist1; inline: = imagelist1; {set overlayindex, up to 4} imagelist1.overlay (); {parameter 1 is the serial number in imagelist; parameter 2 is the optional overlayindex} imagelist1.overlay (); imagelist1.overlay (); imagelist1.overlay ); label1.caption: = 'stateindex: '; label2.caption: = 'overlayindex:'; edit1.text: = '-1'; edit2.text: ='-1'; button1.caption: = 'initialization '; {fill treeview1} with treeview1 do begin align: = alleft; items. add (nil, 'aaa'); items. add (nil, 'bbb '); items. add (nil, 'ccc '); items. add (nil, 'ddd '); items. add (nil, 'Eee '); items. addchild (items [4], '20140901'); items. addchild (items [4], '20140901'); items. addchild (items [4], '20140901'); items. addchild (items [4], '20140901'); end; {specify the icon status} For node in treeview1.items do begin node. imageindex: = 0; {the default icon is 0th} node. selectedindex: = 1; {the selected icon is 1st} node. stateindex: =-1; {status icon none} end; {edit1 control stateindex} procedure tform1.edit1keyup (Sender: tobject; var key: word; shift: tshiftstate ); vaR C: Char; Edit: tedit; begin EDIT: = tedit (sender); C: = CHR (key); if C in ['0 '.. '6'] Then edit. text: = C else edit. text: = '-1'; {character limit} treeview1.selected. stateindex: = strtoint (edit. text); {act on Treeview} end; {edit2 controls overlayindex} procedure tform1.edit2keyup (Sender: tobject; var key: word; shift: tshiftstate); var C: Char; Edit: tedit; begin EDIT: = tedit (sender); C: = CHR (key); if C in ['0 '.. '3'] Then edit. text: = C else edit. text: = '-1'; {character limit} treeview1.selected. overlayindex: = strtoint (edit. text); {act on Treeview} end; Procedure tform1.treeview1change (Sender: tobject; node: ttreenode); begin edit1.text: = inttostr (node. stateindex); edit2.text: = inttostr (node. overlayindex); end; Procedure tform1.button1click (Sender: tobject); begin treeview1.items. clear; formcreate (NiL); end.
 
  
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.