CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2001
    Location
    UK
    Posts
    128

    CTreeCtrl and a linked list or somethink?

    I just can't figure it out. Its probably so simple - but I just can't see it.

    I wan't to be able to store a complete list of data (e.g CString objects for example) in some sort of organisation....so that I can insert it into a CTreeCtrl....and give me a hierachial representation

    I've tried Linked lists and binary tree's...but I can't seem to do it.

    Is there an answer...and simple way?...anyway?..

    Thank you so much for any help you can give me....

    Hours and hours spent playing with linked list

  2. #2
    Join Date
    Aug 2001
    Location
    Minnesota, USA
    Posts
    801
    Here is a base for a tree item class for you to start with:

    Code:
    #include <AfxTempl.h>
    
    class CTreeItem;
    typedef CList<CTreeItem*,CTreeItem*> CTreeItemList;
    
    class CTreeItem
    {
    public:
       CTreeItem();
       ~CTreeItem();
       
       void              AddChild( CTreeItem * p_poChild );
    
    protected:
       CTreeItem *       c_poParent;
       CTreeItemList     c_oChildren;
    };
    The c_poParent will store the parent of each child item, and it will be set in the AddChild function. Also in the AddChild function, you would add the p_poChild variable into the c_oChildren list that you have. Then, you would probably make some iterator class (or else just public functions) to iterate the children of each item. Somewhere you would just have to store one CTreeItem variable, which would be the root item of the tree.

    Chris Richardson

  3. #3
    Join Date
    Jun 2001
    Location
    UK
    Posts
    128

    thanx

    thanx Chris,
    it might work....but I think I might just give up on CTreeCtrls' forever and storing data....life just is to short!...2 days!...my god!!...just playing with linked lists...no more I tell you no more



    Thanx anyway Chris your a star.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured