?
Solved

Load stl list in TTreeView or in TMemoryStream?

Posted on 2006-05-11
4
Medium Priority
?
447 Views
Last Modified: 2012-08-13
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
Comment
Question by:JulioBeta
2 Comments
 
LVL 2

Accepted Solution

by:
pmdw earned 1000 total points
ID: 16755784
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
 

Author Comment

by:JulioBeta
ID: 16767412
Thanks for your clear code.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question