• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 455
  • Last Modified:

Load stl list in TTreeView or in TMemoryStream?

In C++ Builder.
How can I load stl <AnsiString> list in TTreeView?  AND  load stl <AnsiString> list in TMemoryStream?
I need the code, no an explanation.
Regards
0
JulioBeta
Asked:
JulioBeta
1 Solution
 
pmdwCommented:
Hi
try this I  hope this helps

needs the following includes
and TreeView1 on the form
 TTreeView *TreeView1;
//----------------------------------------------------------
#include <list>
#include <iterator>
//----------------------------------------------------------

start function
  TTreeNode *Node1;
  int nodecount;

  std::list<AnsiString> first_list; // make a list for level one
  std::list<AnsiString> second_list; // make a list for level two
  first_list.push_back("one");
  first_list.push_back("two");
  first_list.push_back("three");
  first_list.push_back("four");
  first_list.push_back("five");

  second_list.push_back("one of one");
  second_list.push_back("two of two");
  second_list.push_back("three of three");
  second_list.push_back("four of four");
  second_list.push_back("five of five");


  TreeView1->Items->Clear();// remove any existing nodes
  nodecount= TreeView1->Items->Count; //clean up start @ zero

  //iterators
  std::list<AnsiString>::iterator pos;
  std::list<AnsiString>::iterator pos_two;
  //ready set
  pos_two = second_list.begin();
  //go
  for(pos = first_list.begin();pos != first_list.end();)
  {//begin for loop
    if (nodecount <= 0)
    {// only for the fist node to be added
      TreeView1->Items->Add(NULL,*pos);
    }
    else
    {// add the first list at level one
      TreeView1->Items->Add(TreeView1->Items->Item[0],*pos);
    }
    // get the current first list node
    Node1 = TreeView1->Items->Item[nodecount];
    // add a child from the second list to the node
    TreeView1->Items->AddChild(Node1,*pos_two);
    pos++;
    pos_two++;
    nodecount = nodecount + 2 ; // added two nodes so move on two
  }//end for loop
end function
0
 
JulioBetaAuthor Commented:
Thanks for your clear code.
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now