Treeview and Selected Item

Hello,

How can i access the selected Object index or ChildObject index in a treeview?  It seems differents then the ListBox

  Desactiver1.Enabled := (TAppareils(Treeview1.Selected).Active = 'true');  

This work (Treeview1.Selected), but not when i access one of is childs... i receive an acess violation.

Thanks



FledAsked:
Who is Participating?
 
kretzschmarCommented:
this would be the correct access:

Desactiver1.Enabled := (TAppareils(Treeview1.Selected.Data).Active = 'true');  

meikl ;-)
0
 
alijuniorCommented:
Hi Fled...

What is "TAppareils" ???

The code

  Caption := TreeView1.Selected.Text;

works fine! May be the cast of class TTreeNode to TAppareils raise the error...

The class of childs and "parents" are the same (TTreeNode) in the TreeView.Items... The difference are that the root members has Parent = nil, and childs not.

Post the complete code to help me help you...

[]'s
0
 
FledAuthor Commented:
TAppareils is a user class..  This is the code to fill the treeview...

var
  UnAppareil : TAppareils;
  Node : TTreeNode;
  ChildNode : TTreeNode;
  PlageHaut, PlageBas : string;
begin

    if not CDSAppareils.Active then
        CDSAppareils.Active := true;

    CDSAppareils.First;

    While not CDSAppareils.Eof do
    begin
      UnAppareil := TAppareils.Create;
      Node := TTreeNode.Create(nil);

      UnAppareil.NomLogique     := CDSAppareils.FieldValues['chr_NomLogique'];
      UnAppareil.Manufacturier  := CDSAppareils.FieldValues['chr_Manufacturier'];
      UnAppareil.Identificateur := CDSAppareils.FieldValues['chr_Identificateur'];
      UnAppareil.NoSerie        := CDSAppareils.FieldValues['chr_NoSerie'];
      UnAppareil.NoModele       := CDSAppareils.FieldValues['Chr_NoModele'];
      UnAppareil.Active         := CDSAppareils.FieldValues['chr_Actif'];
      UnAppareil.PlageUtilBas   := CDSAppareils.FieldValues['flo_PlageBas'];
      UnAppareil.PlageUtilHaut  := CDSAppareils.FieldValues['flo_PlageHaut'];
      UnAppareil.Resolution     := CDSAppareils.FieldValues['chr_Resolution'];
      UnAppareil.Exactitude     := CDSAppareils.FieldValues['chr_Exactitude'];

      PlageHaut                 := format('%.1f °C', [UnAppareil.PlageUtilHaut]);
      PlageBas                  := format('%.1f °C', [UnAppareil.PlageUtilBas]);

      Form1.TreeView1.Images    := form1.ImageList1;

      Node := Form1.TreeView1.Items.AddObject(nil, UnAppareil.NomLogique, UnAppareil);

      ChildNode := Form1.Treeview1.Items.AddChildObject(Node, UnAppareil.Identificateur + ' - ' +
                    Trim(UnAppareil.Manufacturier) + ' - ' + 'Serie: ' + UnAppareil.NoSerie
                    + ' - ' + 'Model: ' + UnAppareil.NoModele + ' - ' + 'Exact: ' +
                    UnAppareil.Exactitude + ' - ' + 'Resol: ' + UnAppareil.Resolution + ' - '
                    + 'Plages: ( ' + PlageBas + ' - ' + PlageHaut + ' ) ', UnAppareil);


      if UnAppareil.Active = 'true' then
        begin
          node.ImageIndex     := 2;
          node.SelectedIndex  := 2;
          ChildNode.ImageIndex := 2;
          ChildNode.SelectedIndex := 2;

        end
      else
        begin
          node.ImageIndex     := 3;
          node.SelectedIndex  := 3;
          ChildNode.ImageIndex := 3;
          ChildNode.SelectedIndex := 3;

        end;

       CDSAppareils.next;
    end;

    CDSAppareils.Close;

end;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.