Board index » delphi » VERY URGENT - TTreeView - Insert a image

VERY URGENT - TTreeView - Insert a image

How do i put a image in the TTreeview. I know that a can insert diferents
images for the node is select or not, but a dont know how.

Give some examples, or where i can find them!

There are anyone can help me please!.

Thanks!..

 

Re:VERY URGENT - TTreeView - Insert a image


Quote
"Milenia, Lda." wrote:

> How do i put a image in the TTreeview. I know that a can insert diferents
> images for the node is select or not, but a dont know how.

> Give some examples, or where i can find them!

> There are anyone can help me please!.

> Thanks!..

Are you using a TImageList?

Here is something I got from these forums at an ealier time on this
topic.
I have not tested the code or content..

<MESSAGE>

You should set TreeNode.StateIndex. I think I know why you haven't met
with success yet: The TTreeView component appears to ignore the very
first image in the TImageList.  When you set the StateIndex of a
specific TTreeNode to 0 (indicating that it should display the first
bitmap in the TImageList, nothing is displayed.

This, as far as I know, is a bug. I've worked around it by first loading
a dummy image into the TImageList, followed by the bitmaps of real
interest.

Try the following:

procedure TForm1.FormCreate(Sender: TObject);
begin
  with YourTreeView do
  begin
      for I := 1 to Items.Count-1 do
        with Items[I] do
          StateIndex := 1;
      Selected:=Items[0]
  end
end;

procedure TForm1.YourTreeViewClick(Sender: TObject);
begin
  with YourTreeView.Selected do
    if ImageIndex = 1 then
      ImageIndex := 2
    else
      ImageIndex:=1
end;

That should show you how it works. Note: The

Selected := Items[0]

line is to set TTreeView.Selected to SOMETHING (it defaults to nil, and
I prefer not to keep testing whether Selected = nil when I dostuff with
the TTreeView).

</MESSAGE END>

Hope that helps!

RKr

--
                   \|||/
                   /'^'\
                  ( 0 0 )
--------------oOOO--(_)--OOOo--------------
. Reid Roman                              .
. Delphi Programmer / Analyst             .
. TVisualBasic:=class(None)               .
. May the Source be With You              .
-------------------------------------------
. Auto-By-Tel (http://www.autobytel.com)  .
. Irvine, CA U.S.A                        .
. E-Mail : rkroman (at) pacbell (dot) net .
. or reidr (at) autobytel (dot) com       .
-------------------------------------------

Other Threads