Board index » delphi » TreeView and Custom Icon Images

TreeView and Custom Icon Images

I am attempting to show a treeview and want to insert custom images for the
node, does anyone have an example of setting a custom image for treeview?
Help

Thanks Jim

 

Re:TreeView and Custom Icon Images


J

example of the top of my head

jm

const
    iRootImageIndex = 0;
    iRootSelectedIndex = 1;
    iBranchImageIndex = 2;
    iBranchSelectedIndex = 3;
    iLeafImageIndex = 4;
    iLeafSelectedIndex = 5;

var
    ARoot,
    ABranch,
    ALeaf: TreeNode;
    BranchCount,
    LeafCount: Integer;
begin
    with TreeView1 do
    begin
        Items.Clear;
        Items.BeginUpdate;
        ARoot := AddChild(nil, 'Root');
        ARoot.ImageIndex := iRootImageIndex;
        ARoot.SelectedIndex := iRootSelectedIndex;

        {* add 4 branch nodes to Root of  Tree *}
        for BranchCount := 1 to 4  do
        begin
            ABranch := AddChild(ARoot, 'Branch' + IntToStr(BranchCount));
            ABranch.ImageIndex := iBranchImageIndex;
            ABranch.SelectedIndex := iBranchSelectedIndex;

            {* add 6 leaf nodes to each branch *}
            for LeafCount := 1 to 6 do
            begin
                ALeaf := AddChild(ABranch, 'Leaf' + IntToStr(LeafCount));
                ALeaf.ImageIndex := iLeafImageIndex;
                ALeaf.SelectedIndex := iLeafSelectedIndex;
            end;
        end;
        Items.EndUpdate;
    end;
end;

for this code to work as is -

Shove it in FormCreate or perhaps a ButtonClick
Put a TreeView and an ImageList on the Form
Populate ImageList with 6 custom images;
Set TreeView.Images to ImageList

Quote
James E. Eastham wrote in message news:8aolgf$t4o3@bornews.borland.com...
> I am attempting to show a treeview and want to insert custom images for
the
> node, does anyone have an example of setting a custom image for treeview?

Other Threads