TTreeView StateIndex not working?

Consider the following lines of code:

  MyNode := TreeView1.Selected;
  MyNode.StateIndex := 0;

Shouldn't this display the 0th state image in the image list I have assigned?

How does StateIndex work?
LVL 5
Tom KnowltonWeb developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
hi
as far as i am aware 0 is the first image in the imagelist..

take a look here for lots of delphi info about treeviews:

http://users.iafrica.com/d/da/dart/Delphi/TTreeView/TreeView.html


0
Tom KnowltonWeb developerAuthor Commented:
If the code is compiling okay, then what is it doing...because nothing is changing.  The state index icon is not showing up.

Tom
0
intheCommented:
where are these lines of code?
i mean on what procedure have you put them ?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tom KnowltonWeb developerAuthor Commented:
Here is the source code for my little demo:

You click the button and whatever node you selected gets updated with StateImage 0

The images are coming from ImageList1.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ImgList, ComCtrls;

type
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    ImageList1: TImageList;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  TempNode : TTreeNode;
begin
  //TempNode equals what is selected in the TreeView
  TempNode := TreeView1.Selected;
  //Assign image 0 to TempNode.StatIndex
  TempNode.StateIndex := 0;
end;

end.
0
Tom KnowltonWeb developerAuthor Commented:
The problem seems to be with the 0th Image only.  Image 1 seems to work.

For example:

TempNode := TreeView1.Selected;
TempNode.StateIndex := 0;

The code above seems to do nothing at run time.

However:

TempNode := TreeView1.Selected;
TempNode.StateIndex := 1;

This works just fine.

There seems to be a bug with assigning the 0th item in an imagelist to the StateIndex of a TreeView.

Hmmm....

0
intheCommented:
ok whew got it working :

procedure TForm1.Button1Click(Sender: TObject);
var
  TempNode : TTreeNode;
begin
  //TempNode equals what is selected in the TreeView
  TempNode := TreeView1.Selected;
  TempNode.selectedindex := 1;
  //Assign image 0 to TempNode.StatIndex
  TempNode.StateIndex := 0;
  Treeview1.refresh;
  treeview1.SetFocus;
end;

let me know if this is what your after
Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tom KnowltonWeb developerAuthor Commented:
Good job.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.