Board index » delphi » Treeview ImageIndex

Treeview ImageIndex

HI,

I'v added a node with one child like this ..

Node := Treeview1.Items.Add(nil,'New Parent');
Treeview1.Items.AddChild(Node,'Child to new parent');

How do I go about changing the image index of the new child I just
created ? I know Treeview1.Items[i].imageindex := index but how do I
get item index ?

 

Re:Treeview ImageIndex


Quote
>I'v added a node with one child like this ..

>Node := Treeview1.Items.Add(nil,'New Parent');
>Treeview1.Items.AddChild(Node,'Child to new parent');

>How do I go about changing the image index of the new child I just
>created ? I know Treeview1.Items[i].imageindex := index but how do I
>get item index ?

Just do the same thing again. Instead of doing the AddChild that way,
do

ChildNode := Treeview1.Items.AddChild(Node,'Child to new parent');

Then you can access the imageindex with

ChildNode.ImageIndex

Michael Burton
AMS Services, Inc.
Coeur d'Alene, Idaho

Re:Treeview ImageIndex


On Tue, 09 Mar 1999 07:21:08 GMT, Anton@(Remove me)osi.co.za (Anton)
wrote:

Quote
>HI,

>I'v added a node with one child like this ..

>Node := Treeview1.Items.Add(nil,'New Parent');
>Treeview1.Items.AddChild(Node,'Child to new parent');

>How do I go about changing the image index of the new child I just
>created ? I know Treeview1.Items[i].imageindex := index but how do I
>get item index ?

the definition of TTreeNode.addchilde is:

function AddChild(Node: TTreeNode; const S: string): TTreeNode;

It returns the added node.

Thus

   Node := Treeview1.Items.Add(nil,'New Parent');
   newnode:=Treeview1.Items.AddChild(Node,'Child to new parent');

   newnode.imageindex:=index;

or more generally:

  Node := Treeview1.Items.Add(nil,'New Parent');
  with Treeview1.Items.AddChild(Node,'Child to new parent') do begin
        imageindex:=index;
        selectedindex:=index;
        // other node initialization here.
  end;

Re:Treeview ImageIndex


In article <36e5c9fd.9612...@196.4.160.8>, Anton@(Remove me)osi.co.za (Anton)
writes:

Quote
>I'v added a node with one child like this ..

>Node := Treeview1.Items.Add(nil,'New Parent');
>Treeview1.Items.AddChild(Node,'Child to new parent');

>How do I go about changing the image index of the new child I just
>created ? I know Treeview1.Items[i].imageindex := index but how do I
>get item index ?

Just as the Add method does, the AddChild also returns the TTreeNode it has
created :-

var
  TN : TTreeNode;

  TN := Treeview1.Items.AddChild(Node,'Child to new parent');
  TN.ImageIndex := ???  // the index of the image in the TImageList.
  TN.SelectedIndex := TN.ImageIndex; // or some other for when the node is
selected.

The TImageList must be allocated to the TTreeView.Images property. When you
have selected the TImageList from thr components palette you can then load
bitmap files to that imagelist.

Alan Lloyd
alangll...@aol.com

Re:Treeview ImageIndex


drop a TImage object on the form then set TTreeView ImageList to the
TImagelist  then fill it with your bmp's

Hope this answers your question or points you the right direction

CT

Remove me osi.co.za (Anton) wrote in message
<36e5c9fd.9612...@196.4.160.8>...

Quote
>HI,

>I'v added a node with one child like this ..

>Node := Treeview1.Items.Add(nil,'New Parent');
>Treeview1.Items.AddChild(Node,'Child to new parent');

>How do I go about changing the image index of the new child I just
>created ? I know Treeview1.Items[i].imageindex := index but how do I
>get item index ?

Other Threads