TTIWAdvTreeView

Hi 


I am looking for some help 

i have file Paths in a database field . i wand to create a treeview based on the file structure.



regards
ettienne

Hi,


Can you please have a look at the "Demo AdvTreeview" page of the "TMS IW FeaturesDemo" for a full working example of how to use the TAdvTreeview component?

Hi Bart  thanks for the reply


I have and it doesn't make sense to me the demo only adds the tree information with static declared 

tree nodes. What i am not understanding is how to programatically find a node and adding a new child to the parent node . pleas look at my input  a small sample project to add this programatically would help.

I have written code using the standard delphi VCL which works fine . But it seems the same logic does not apply to your treeview and obviously i need to use your component.

procedure TformAdvTreeView.IWAppFormCreate(Sender: TObject);
var
  N, NC, NCC: TAdvTreeNode;
begin
  FrameTopFrame1.Align := alTop;
  FrameLeftFrame1.Align := alLeft;

  TIWAdvTreeView1.Items.Clear;

  N := TIWAdvTreeView1.Items.Add('Folder 1');
  N.Hint := 'Folder 1';
  N.ImageURL := '/files/f/g/h/j/folder.gif';
  N.ImageCollapsedURL := '/files/f/g/h/j/folder-closed.gif';
  N.Tag := 1;
  N.IsExpanded := False;

  NC := N.AddChild('/files/b/h/f/d/File A');
  NC.Hint := 'File A';
  NC.ImageURL := '/files/b/h/f/d/file.png';
  NC.Tag := 2;

  NC := N.AddChild('/files/b/h/f/d/File B');
  NC.Hint := 'File B';
  NC.ImageURL := '/files/file.png';
  NC.Tag := 3;

  N := TIWAdvTreeView1.Items.Add('Folder 2');
  N.Hint := 'Folder 2';
  N.ImageURL := '/files/folder.gif';
  N.ImageCollapsedURL := '/files/folder-closed.gif';
  N.Tag := 4;
  N.IsExpanded := True;

  NC := N.AddChild('Subfolder 1');
  NC.Hint := 'Subfolder 1';
  NC.ImageURL := '/files/folder.gif';
  NC.ImageCollapsedURL := '/files/folder-closed.gif';
  NC.Tag := 5;

  NCC := NC.AddChild('File C');
  NCC.Hint := 'File C';
  NCC.ImageURL := '/files/file.png';
  NCC.Tag := 6;

  N := TIWAdvTreeView1.Items.Add('Options');
  N.Hint := 'Options';
  N.ImageURL := '/files/options.png';
  N.Tag := 7;
  N.IsExpanded := True;

  NC := N.AddChild('Operating System');
  NC.Hint := 'Select your current operating system.';
  NC.ImageURL := '/files/pc.gif';
  NC.Tag := 8;

  NCC := NC.AddChild('Windows XP');
  NCC.Hint := 'Windows XP';
  NCC.ImageURL := '/files/windows.png';
  NCC.Tag := 9;
  NCC.NodeType := ntRadioButton;

  NCC := NC.AddChild('Windows Vista');
  NCC.Hint := 'Windows Vista';
  NCC.ImageURL := '/files/windowsvista.png';
  NCC.Tag := 10;
  NCC.NodeType := ntRadioButton;

  NCC := NC.AddChild('Windows 7');
  NCC.Hint := 'Windows 7';
  NCC.ImageURL := '/files/windows7.png';
  NCC.Tag := 11;
  NCC.Checked := True;
  NCC.NodeType := ntRadioButton;

  NC := N.AddChild('Browsers');
  NC.Hint := 'Select the currently installed browsers.';
  NC.ImageURL := '/files/world.png';
  NC.Tag := 12;

  NCC := NC.AddChild('Chrome');
  NCC.Hint := 'Google Chrome';
  NCC.ImageURL := '/files/chrome.png';
  NCC.Tag := 13;
  NCC.Checked := True;
  NCC.NodeType := ntCheckBox;

  NCC := NC.AddChild('FireFox');
  NCC.Hint := 'Mozilla FireFox';
  NCC.ImageURL := '/files/firefox.png';
  NCC.Tag := 14;
  NCC.NodeType := ntCheckBox;

  NCC := NC.AddChild('Internet Explorer');
  NCC.Hint := 'Microsoft Internet Explorer';
  NCC.ImageURL := '/files/ie.png';
  NCC.Tag := 15;
  NCC.Checked := True;
  NCC.NodeType := ntCheckBox;

  NCC := NC.AddChild('Opera');
  NCC.Hint := 'Opera';
  NCC.ImageURL := '/files/opera.png';
  NCC.Tag := 16;
  NCC.NodeType := ntCheckBox;

  NCC := NC.AddChild('Safari');
  NCC.Hint := 'Apple Safari';
  NCC.ImageURL := '/files/safari.png';
  NCC.Tag := 17;
  NCC.NodeType := ntCheckBox;

  N := TIWAdvTreeView1.Items.Add('TMS Software');
  N.Hint := 'Link to the TMS Software site';
  N.ImageUrl := '/files/tms.png';
  N.Tag := 18;

end;



regards ettienne

Unfortunately there's currently no sample available to dynamically add new nodes.

Note that you can use the HasChildren, GetFirstChild and GetNextSibling methods of the TAdvTreeNode object to iterate through any Node's child nodes and then use AddChild to add a new item.

Thanks


I got it working , however i need to find a node and add to that specific node and that is where i am stuck.

Will give it another try today

regards
ettienne

Hi Bart


I cannot get the getnextsibling to work it always returns nil. Please give me a small sample project  so i can get this project done.

Regards

ettienne

Hi Bart


I am at my wits end . In the delphi vcl it is simple to do 


all i want to do is 
data from the DB

C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.AI
C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.JPEG
C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.PDF
C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO_COV.PDF
C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO_LR.PDF
C:\A_ORIGINBLU\DATA\BIZZCO\THUMBS.DB


Treeview 
    C:</div>
       A_ORIGINBLU 
                            DATA
                                    BIZZCO
                                           BIZZCO.JPEG
                                           BIZZCO.PDF
                                           BIZZCO_COV.PDF
                                           BIZZCO_LR.PDF
                                           THUMBS.DB


The main question i have is how do i move to a specific point in the treeview add the next child and keep on doing this dynamically until i have done all the records in the table.

I have been at this since Monday . Please assist. I have tried every piece of code i could find but cannot see the logic in your tree view. 


Regards
ettienne


Here is a code example.
I'm sure the code could be improved but it seems to be working as expected with the sample data you provided.


procedure TIWForm1.IWAppFormCreate(Sender: TObject);
var
  I, J, P: Integer;
  Value, Part: string;
  ParentNode: TAdvTreeNode;
  DBData: TStringList;

  function FindNode(ParentNode: TAdvTreeNode; NodeText: string): TAdvTreeNode;
  var
    I: Integer;
    Node: TAdvTreeNode;
  begin
    Result := nil;

    if ParentNode.HasChildren then
    begin
      Node := ParentNode.getFirstChild;
      if Node.Text = NodeText then
        Result := Node
      else
      begin
        repeat
          Node := ParentNode.getNextSibling;
          if Assigned(Node) then
          begin
            if Node.Text = NodeText then
              Result := Node
          end;
        until (Node = nil);
      end;
    end;

    if not Assigned(Result) then
      Result := ParentNode.AddChild(NodeText);
  end;

  function FindRootNode(NodeText: string): TAdvTreeNode;
  var
    I: Integer;
  begin
    Result := nil;

    if TIWAdvTreeView1.Items.Count = 0 then
      Result := TIWAdvTreeView1.Items.Add(NodeText)
    else
    begin
      for I := 0 to TIWAdvTreeView1.Items.Count - 1 do
      begin
        if TIWAdvTreeView1.Items.Text = NodeText then
          Result := TIWAdvTreeView1.Items;
      end;
    end;
  end;

begin

  DBData := TStringList.Create;
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.AI');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.JPEG');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO_COV.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO_LR.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\THUMBS.DB');

  ParentNode := nil;

  for I := 0 to DBData.Count - 1 do
  begin
    Value := DBData;
    J := 0;
    while pos('', Value) > 0 do
    begin
      p := pos('', Value);
      Part := copy(Value, 1, p - 1);
      Delete(Value, 1, p);
      if J = 0 then
        ParentNode := FindRootNode(Part)
      else
        ParentNode := FindNode(ParentNode, Part);
      J := J + 1;
    end;

    if Assigned(ParentNode) then
      ParentNode.AddChild(Value);
  end;
  DBData.Free;
end;

Thanks Bart 


I am well versed in delphi . Just struggled with this one . I will enhance if i need

Thanks
for your help

hi bart 


Thanks again 

I  like your help again

on this it now had a different parent . could you help please I have added more lines to the DBdata but with different dataprocedure TIWForm1.IWAppFormCreate(Sender: TObject);
var
  I, J, P: Integer;
  Value, Part: string;
  ParentNode: TAdvTreeNode;
  DBData: TStringList;

  function FindNode(ParentNode: TAdvTreeNode; NodeText: string): TAdvTreeNode;
  var
    I: Integer;
    Node: TAdvTreeNode;
  begin
    Result := nil;

    if ParentNode.HasChildren then
    begin
      Node := ParentNode.getFirstChild;
      if Node.Text = NodeText then
        Result := Node
      else
      begin
        repeat
          Node := ParentNode.getNextSibling;
          if Assigned(Node) then
          begin
            if Node.Text = NodeText then
              Result := Node
          end;
        until (Node = nil);
      end;
    end;

    if not Assigned(Result) then
      Result := ParentNode.AddChild(NodeText);
  end;

  function FindRootNode(NodeText: string): TAdvTreeNode;
  var
    I: Integer;
  begin
    Result := nil;

    if ttvFiles.Items.Count = 0 then
      Result := ttvFiles.Items.Add(NodeText)
    else
    begin
      for I := 0 to ttvFiles.Items.Count - 1 do
      begin
        if ttvFiles.Items.item.Text = NodeText then
          Result := ttvFiles.Items.Item;
      end;
    end;
  end;

begin

  DBData := TStringList.Create;
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.AI');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.JPEG');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO_COV.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO_LR.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\THUMBS.DB');
  DBData.Add('C:\A_ORIGINBLU\DATA\BLUE PETER\WEB UPDATES MARCH 2014\BRUNCH_MENU.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BLUE PETER\WEB UPDATES MARCH 2014\CARVERY_BUFFET_1.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BLUE PETER\WEB UPDATES MARCH 2014\CARVERY_BUFFET_2.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BLUE PETER\WEB UPDATES MARCH 2014\DINNER_DANCE.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BLUE PETER\WEB UPDATES MARCH 2014\FUNCTION_TERMSCONDITIONS.PDF');

  ParentNode := nil;

  for I := 0 to DBData.Count - 1 do
  begin
    Value := DBData;
    J := 0;
    while pos('', Value) > 0 do
    begin
      p := pos('', Value);
      Part := copy(Value, 1, p - 1);
      Delete(Value, 1, p);
      if J = 0 then
        ParentNode := FindRootNode(Part)
      else
        ParentNode := FindNode(ParentNode, Part);
      J := J + 1;
    end;

    if Assigned(ParentNode) then
    begin
      ParentNode.AddChild(Value);
    end;
  end;
  DBData.Free;

end;

I will also look again tomorrow


thanks
Again

Hi bart


The output should look like this 

c:
  A_ORIGINBLU
          DATA
            BIZZCO
                BIZZCO.AI 
                BIZZCO.JPEG 
                BIZZCO.PDF
                BIZZCO_COV.PDF
                BIZZCO_LR.PDF
                THUMBS.DB
            BLUE PETER
                   WEB UPDATES MARCH 2014
                                BRUNCH_MENU.PDF
                                CARVERY_BUFFET_1.PDF
                                CARVERY_BUFFET_2.PDF
                                DINNER_DANCE.PDF
                                FUNCTION_TERMSCONDITIONS.PDF

Here's my updated code.
Please make sure to use GetNextChild(ChildNode) instead of GetNextSibling.


procedure TIWForm1.IWAppFormCreate(Sender: TObject);
var
  I, J, P: Integer;
  Value, Part: string;
  ParentNode: TAdvTreeNode;
  DBData: TStringList;

  function FindNode(ParentNode: TAdvTreeNode; NodeText: string): TAdvTreeNode;
  var
    Node: TAdvTreeNode;
  begin
    Result := nil;

    if ParentNode.HasChildren then
    begin
      Node := ParentNode.getFirstChild;
      if Node.Text = NodeText then
      begin
        Result := Node;
      end
      else
      begin
        repeat
          Node := ParentNode.getNextChild(Node);
          if Assigned(Node) then
          begin
            if Node.Text = NodeText then
            begin
              Result := Node;
            end;
          end;
        until (Node = nil);
      end;
    end;

    if not Assigned(Result) then
      Result := ParentNode.AddChild(NodeText);
  end;

  function FindRootNode(NodeText: string): TAdvTreeNode;
  var
    I: Integer;
  begin
    Result := nil;

    if TIWAdvTreeView1.Items.Count = 0 then
      Result := TIWAdvTreeView1.Items.Add(NodeText)
    else
    begin
      for I := 0 to TIWAdvTreeView1.Items.Count - 1 do
      begin
        if TIWAdvTreeView1.Items.Text = NodeText then
          Result := TIWAdvTreeView1.Items;
      end;
    end;
  end;

begin

  DBData := TStringList.Create;
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.AI');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.JPEG');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO_COV.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\BIZZCO_LR.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BIZZCO\THUMBS.DB');
  DBData.Add('C:\A_ORIGINBLU\DATA\BLUE PETER\WEB UPDATES MARCH 2014\BRUNCH_MENU.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BLUE PETER\WEB UPDATES MARCH 2014\CARVERY_BUFFET_1.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BLUE PETER\WEB UPDATES MARCH 2014\CARVERY_BUFFET_2.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BLUE PETER\WEB UPDATES MARCH 2014\DINNER_DANCE.PDF');
  DBData.Add('C:\A_ORIGINBLU\DATA\BLUE PETER\WEB UPDATES MARCH 2014\FUNCTION_TERMSCONDITIONS.PDF');

  ParentNode := nil;

  for I := 0 to DBData.Count - 1 do
  begin
    Value := DBData;
    J := 0;
    while pos('', Value) > 0 do
    begin
      p := pos('', Value);
      Part := copy(Value, 1, p - 1);
      Delete(Value, 1, p);
      if J = 0 then
        ParentNode := FindRootNode(Part)
      else
        ParentNode := FindNode(ParentNode, Part);
      J := J + 1;
    end;

    if Assigned(ParentNode) then
      ParentNode.AddChild(Value);
  end;
  DBData.Free;
end;

thanks for all your efforts bart it is working Fine now


regards

ettienne

Thank you for confirming this has been resolved.

No problem


Hi bart 


Just another little issue . The control is working fine . it seems intermittent but every so often it doesn't draw the + - to expand or contract although it does expand or contract and the lines from the parent to the child does not draw.  I tried async and normal mode. tried to resync/repaaint/redraw without success

can you assist please

We are not aware of such an issue with the TIWAdvTreeView.
Can you please provide a ready to run sample project that demonstrates the issue so I can further investigate this?

Please also provide the following information:
- The version of Delphi you are using
- The version of IntraWeb you are using
- The name and version of the browser you are using

thanks bart . how do i send the sample the sample. 


I am using delphi XE4
intraweb 14
browswers chrome and ie

regards
ettienne

I Mean Delphi EX2


here is a sample link http://129.232.198.212:8888

regards