Link to home
Start Free TrialLog in
Avatar of Tom Knowlton
Tom KnowltonFlag for United States of America

asked on

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?
Avatar of inthe
inthe

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


Avatar of Tom Knowlton

ASKER

If the code is compiling okay, then what is it doing...because nothing is changing.  The state index icon is not showing up.

Tom
where are these lines of code?
i mean on what procedure have you put them ?
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.
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....

ASKER CERTIFIED SOLUTION
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Good job.