CTreeObject class
-
Hi all of you. I have to develop a project, where I need to use a CTree object, something very similar to CTreeCtrl. But this object, will contain only 2 things on every items: int and CString (just like CTreeCtrl does). I avoid to use CTreeCtrl, because this object will not be an visible object, just hold data as a tree structure. Could you advice me what should I use in this case ? I mean, in this object I need to store something like this: 4 root --- 5 child1 --------6 child11 --------7 child12 --------8 child13 --- 9 child2 --- 10 child3 --------12 child31 --------13 child32 --------14 child33 --- 11 child4 Any advice will be welcome, but I have to keep this object simple, as being possible ... Yes, I could use a CTreeCtrl, but this object will had an ID, will be derived from CWnd, etc. ... and my data must keep it only in memory, not inside of CWnd control ... Kindly thank you.
-
Hi all of you. I have to develop a project, where I need to use a CTree object, something very similar to CTreeCtrl. But this object, will contain only 2 things on every items: int and CString (just like CTreeCtrl does). I avoid to use CTreeCtrl, because this object will not be an visible object, just hold data as a tree structure. Could you advice me what should I use in this case ? I mean, in this object I need to store something like this: 4 root --- 5 child1 --------6 child11 --------7 child12 --------8 child13 --- 9 child2 --- 10 child3 --------12 child31 --------13 child32 --------14 child33 --- 11 child4 Any advice will be welcome, but I have to keep this object simple, as being possible ... Yes, I could use a CTreeCtrl, but this object will had an ID, will be derived from CWnd, etc. ... and my data must keep it only in memory, not inside of CWnd control ... Kindly thank you.
You could use a structure as below -
struct TreeNode
{
int i;
CString str;
std::vector children;
};Create one instance of
TreeNode
that would be the root. The root can then have children who can have children etc. You could usestd::string
orstd::wstring
instead ofCString
. You can use thepush_back
oremplace_back
methods to add children.«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
-
You could use a structure as below -
struct TreeNode
{
int i;
CString str;
std::vector children;
};Create one instance of
TreeNode
that would be the root. The root can then have children who can have children etc. You could usestd::string
orstd::wstring
instead ofCString
. You can use thepush_back
oremplace_back
methods to add children.«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)