Board index » delphi » TTreeview -- changing image at runtime

TTreeview -- changing image at runtime

Whenever my treeview expands, whether by a double-click on the node, or
opening it through the + icon, I want my image to change.  I've tried on
OnCollapsed, OnCollapsing, OnExpanded, OnExpanding, the mouseup event etc,
but the node only displays the expanded image AFTER I click on another node
in the treeview. Still searching for a solution.  Hope someone can help.

Paul
pwhol...@prodigy.net

 

Re:TTreeview -- changing image at runtime


Quote
>Whenever my treeview expands, whether by a double-click on the node, or
>opening it through the + icon, I want my image to change.  I've tried on
>OnCollapsed, OnCollapsing, OnExpanded, OnExpanding, the mouseup event etc,
>but the node only displays the expanded image AFTER I click on another node
>in the treeview. Still searching for a solution.  Hope someone can help.

Sounds like yo need to call Invalidate or InvalidateRect after you changed
the image?

Re:TTreeview -- changing image at runtime


I'm not sure I understand your problem but
maybe this could help:
try on the GetImageIndex event (get the image of the node when NOT
selected)
or on the GetSelectedIndex event (get the image of the node when selected)
like this :

procedure Tform1.Treeview1GetImageIndex(Sender: TObject;
  Node: TTreeNode);
begin
     Case Node.Level of
        0: begin
              Node.ImageIndex := 1;
              Node.SelectedIndex:=2;
           end;
        1: begin
              Node.ImageIndex := 3;
              Node.SelectedIndex := 4;
           end;
     end;
end;

ImageIndex : image when node is not selected
SelectedIndex : image when node is selected

Paul Holmes <pwhol...@prodigy.net> a crit dans l'article
<73aqsk$5...@forums.borland.com>...

Quote
> Whenever my treeview expands, whether by a double-click on the node, or
> opening it through the + icon, I want my image to change.  I've tried on
> OnCollapsed, OnCollapsing, OnExpanded, OnExpanding, the mouseup event
etc,
> but the node only displays the expanded image AFTER I click on another
node
> in the treeview. Still searching for a solution.  Hope someone can help.

> Paul
> pwhol...@prodigy.net

Re:TTreeview -- changing image at runtime


Try caling the node's Invalidate method after you change the image index to
force a redraw.  I ran into this problem some time ago and this worked for me.

Darren W. Clarke

Quote
Paul Holmes wrote:
> Whenever my treeview expands, whether by a double-click on the node, or
> opening it through the + icon, I want my image to change.  I've tried on
> OnCollapsed, OnCollapsing, OnExpanded, OnExpanding, the mouseup event etc,
> but the node only displays the expanded image AFTER I click on another node
> in the treeview. Still searching for a solution.  Hope someone can help.

> Paul
> pwhol...@prodigy.net

Other Threads