Fled
asked on
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.Sele cted).Acti ve = 'true');
This work (Treeview1.Selected), but not when i access one of is childs... i receive an acess violation.
Thanks
How can i access the selected Object index or ChildObject index in a treeview? It seems differents then the ListBox
Desactiver1.Enabled := (TAppareils(Treeview1.Sele
This work (Treeview1.Selected), but not when i access one of is childs... i receive an acess violation.
Thanks
ASKER
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_NomLog ique'];
UnAppareil.Manufacturier := CDSAppareils.FieldValues[' chr_Manufa cturier'];
UnAppareil.Identificateur := CDSAppareils.FieldValues[' chr_Identi ficateur'] ;
UnAppareil.NoSerie := CDSAppareils.FieldValues[' chr_NoSeri e'];
UnAppareil.NoModele := CDSAppareils.FieldValues[' Chr_NoMode le'];
UnAppareil.Active := CDSAppareils.FieldValues[' chr_Actif' ];
UnAppareil.PlageUtilBas := CDSAppareils.FieldValues[' flo_PlageB as'];
UnAppareil.PlageUtilHaut := CDSAppareils.FieldValues[' flo_PlageH aut'];
UnAppareil.Resolution := CDSAppareils.FieldValues[' chr_Resolu tion'];
UnAppareil.Exactitude := CDSAppareils.FieldValues[' chr_Exacti tude'];
PlageHaut := format('%.1f °C', [UnAppareil.PlageUtilHaut] );
PlageBas := format('%.1f °C', [UnAppareil.PlageUtilBas]) ;
Form1.TreeView1.Images := form1.ImageList1;
Node := Form1.TreeView1.Items.AddO bject(nil, UnAppareil.NomLogique, UnAppareil);
ChildNode := Form1.Treeview1.Items.AddC hildObject (Node, UnAppareil.Identificateur + ' - ' +
Trim(UnAppareil.Manufactur ier) + ' - ' + '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;
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['
UnAppareil.Manufacturier := CDSAppareils.FieldValues['
UnAppareil.Identificateur := CDSAppareils.FieldValues['
UnAppareil.NoSerie := CDSAppareils.FieldValues['
UnAppareil.NoModele := CDSAppareils.FieldValues['
UnAppareil.Active := CDSAppareils.FieldValues['
UnAppareil.PlageUtilBas := CDSAppareils.FieldValues['
UnAppareil.PlageUtilHaut := CDSAppareils.FieldValues['
UnAppareil.Resolution := CDSAppareils.FieldValues['
UnAppareil.Exactitude := CDSAppareils.FieldValues['
PlageHaut := format('%.1f °C', [UnAppareil.PlageUtilHaut]
PlageBas := format('%.1f °C', [UnAppareil.PlageUtilBas])
Form1.TreeView1.Images := form1.ImageList1;
Node := Form1.TreeView1.Items.AddO
ChildNode := Form1.Treeview1.Items.AddC
Trim(UnAppareil.Manufactur
+ ' - ' + '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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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