When using BeginUpdate / EndUpdate you are speeding up the process of building the treeview, yet it implies that the internal node structure creation is bundled into an endupdate. You need to use the GetFirst outside of the BeginUpdate / EndUpdate, or remove the BeginUpdate / EndUpdate or access the Nodes collection directly.
Unfortunately no, but if you are not loading many nodes performance shouldn't be to mich affected, you could use 2 BeginUpdate / EndUpdates blocks. One for adding the nodes and the second for manipulation of existing nodes. The nodestructure will be available in the second loop.
In the same component I have a problem with the 'Checked' values. I use code like below to cascade the 'Checked' values to lower nodes, but those events are never fired. Why?
// fill nodes
TVprogrammas.ClearNodes;
HoofdNode := TVprogrammas.AddNode;
HoofdNode.Text[0] := 'Programma''s';
HoofdNode.Extended := True;
programmas := Data.ClientConnectie.Client.List<Tprogrammas>('$orderby=naam');
Try
if programmas.Count>0 then
begin
for nProgrammaTeller:=0 to programmas.Count-1 do
begin
programmanode := TVprogrammas.AddNode(HoofdNode);
programmanode.Text[0] := programmas[nProgrammaTeller].naam;
programmanode.CheckTypes[0] := tvntCheckBox;
programmanode.Checked[0] := False;
programmanode.Text[1] := IntToStr(programmas[nProgrammaTeller].programmasid);
programmanode.Text[2] := '0';
end;
end;
Finally
programmas.Free;
End;
// Check node
procedure TFormHoofd.TVlicentiesAfterCheckNode(Sender: TObject;
ANode: TAdvTreeViewVirtualNode; AColumn: Integer);
var
ChildNode: TAdvTreeViewNode;
begin
ChildNode := ANode.Node.GetFirstChild;
while ChildNode <> nil do
begin
Childnode.Checked[AColumn] := True;
Childnode := ChildNode.GetNextSibling;
end;
end;
// Uncheck node
procedure TFormHoofd.TVlicentiesAfterUnCheckNode(Sender: TObject;
ANode: TAdvTreeViewVirtualNode; AColumn: Integer);
var
ChildNode: TAdvTreeViewNode;
begin
ChildNode := ANode.Node.GetFirstChild;
while ChildNode <> nil do
begin
Childnode.Checked[AColumn] := False;
Childnode := ChildNode.GetNextSibling;
end;
end;
If you refer to the events never get called when programmatically checking a node then this is by design. Events are never triggered when programmatically changing a value, only with user interaction.
No, I don't mean programmatically. I fill the nodes in a way decribed above. I forgot to mention that their is MUCH more code that fills different childs from the programmanodes in the same way. I then check a node (by user-interaction) and the events don't get triggered.
Hi, sorry for the inconvenience Pieter, but I messed up. I have two TreeViews and I programmed the events in the other treeview.... So they don't get fired....
I do have two more questions though. - Can I switch a complete branch of a tree on of off with one click (by cascading down all the children and their children etc). - Can the state of the checkbox reflect that not all children are switched on or off? Normally one sees a little square in the box when not all are switched on.
I managed to solve my first question with a piece of recursive code. My second question still stands, though, hopefully you can answer that one:
- Can the state of the checkbox reflect that not all children are
switched on or off? Normally one sees a little square in the box when
not all are switched on.
The state of the checkbox can unfortunately not be set to mixed mode as this is not supported in FireMonkey. We will investigate if we can add support for this.