• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1085
  • Last Modified:

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?
0
Tom Knowlton
Asked:
Tom Knowlton
  • 4
  • 3
1 Solution
 
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
 
Tom KnowltonWeb developerAuthor Commented:
Good job.
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now