Jump to content

Load treeview from db


cptngrb

Recommended Posts

I load in treeview my data from database and i want add childs on expand node. To do this in fist time  add node and if has a children add empty child node to get a plus, but when expand node for a short time there is an empty node, and then the real children. How can this be avoided?

procedure TMainForm.LoadChilds(const ANodeID: integer; const ANode: TUniTreeNode);
var
  Node: TUniTreeNode;
  NodeData: PVSTRecord;
  FirstStep: boolean;
begin
  if Assigned(ANode) then
  if PVSTRecord(ANode.Data).Expanded then exit;
  trView.BeginUpdate;
  try
    with UniMainModule.ODS do begin
      Close;
      DeleteVariables;
      DeclareVariable('acur', otCursor);
      DeclareAndSet('aid_parent', otInteger, ANodeID);
      DeclareAndSet('aid_user', otInteger, ID_USER);
      Open;
      FirstStep:= True;
      while not eof do begin
        if FirstStep then
        begin
          if Assigned(ANode) then
          begin
            if ANode.HasChildren then begin
              Node:= ANode.GetFirstChild;
              Node.Text:= FieldByName('name_').AsString;
            end
            else
            Node:= trView.Items.Add(ANode, FieldByName('name_').AsString);
          end
          else
          Node:= trView.Items.Add(ANode, FieldByName('name_').AsString);
          FirstStep:= False;
        end
        else
        begin
          Node:= trView.Items.Add(ANode, FieldByName('name_').AsString);
        end;

        if FieldByName('child_cnt').AsInteger > 0 then
        //Node.HasChildren:= (FieldByName('child_cnt').AsInteger > 0);
          trView.Items.Add(Node, '');
        new(NodeData);
        NodeData.NodeID := FieldByName('id_node').AsInteger;
        NodeData.NodeParentID:= FieldByName('id_par').AsInteger;
        NodeData.NodeName := FieldByName('name_').AsString;
        NodeData.Count := FieldByName('child_cnt').AsInteger;
        NodeData.Expanded:= False;
        NodeData.Read:= 1;
        NodeData.NodeType:= FieldByName('id_type').AsInteger;
        NodeData.ShablonID:= FieldByName('id_shablon').AsInteger;
        Node.Data:= NodeData;
        Next;
      end;
      CloseAll;
    end;
    if Assigned(ANode) then
    PVSTRecord(ANode.Data).Expanded:= True;
  finally
    trView.EndUpdate;
  end;

end;

   

Link to comment
Share on other sites

21 minutes ago, cptngrb said:

I load in treeview my data from database and i want add childs on expand node. To do this in fist time  add node and if has a children add empty child node to get a plus, but when expand node for a short time there is an empty node, and then the real children. How can this be avoided?

Hello,

Can you please specify first, which edition and build of UniGUI are you using?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...