-
October 22nd, 2003, 12:27 AM
#1
ctreectrl to clistbox
I want to convert my current tree to a list format.
example
Tree:
+Group One
|---One
|---Two
|---Three
|---Four
+Group Two
|---A
|---B
|---C
|---D
to
List:
Group One
One
Two
Three
Four
Group Two
A
B
C
D
I am pretty sure i have to create a loop and call GetItemText(), but i am not sure how to properly do this.
PS Please post an example (not that advanced programer).
-
October 22nd, 2003, 02:03 AM
#2
In CTreeCtrl u have a function GetNextItem with flag TVGN_ROOT
insert this item in listbox or listctrl
then call funcion ItemHasChildren it will return that either this item has child item's or not...
if it has childern then call GetNextItem with flag TVGN_CHILD
repeat this process untill u get NULL from GetNextItem
-
October 22nd, 2003, 02:22 AM
#3
-
October 22nd, 2003, 06:15 PM
#4
so far i have got this code
Code:
HTREEITEM hItem, hRootItem, hNextItem;
hRootItem = m_tree.GetNextItem(hItem,TVGN_ROOT);
if (hRootItem)
m_list.AddString(m_tree.GetItemText(hRootItem));
if (m_tree.ItemHasChildren(hRootItem)){
while (hNextItem = m_tree.GetNextItem(hRootItem, TVGN_CHILD)){
m_list.AddString(m_tree.GetItemText(hNextItem));
}
}
but m_tree.GetNextItem(hRootItem, TVGN_CHILD) is never returning null (making it a infinite loop)
Last edited by the-griff; October 22nd, 2003 at 06:29 PM.
-
October 22nd, 2003, 06:33 PM
#5
Originally posted by the-griff
but m_tree.GetNextItem(hRootItem, TVGN_CHILD) is never returning null (making it a infinite loop)
Yes, because GetNextItem() with TVGN_CHILD will always return the first child of hRootItem. You should get only the first child, and then call GetNextItem() with TVGN_NEXT in your loop to get the next sibling.
-
October 22nd, 2003, 07:08 PM
#6
TVGN_NEXT also results in a infinite loop
-
October 22nd, 2003, 07:20 PM
#7
That's strange. Can you post your code? And BTW: If you use TVGN_NEXTVISIBLE, you don't need any recursion and changing between next child / next sibling: Just walk through your tree using TVGN_NEXTVISIBLE and starting at the root, and you will get a linear list of all items as they appear in the hierarchy.
-
October 22nd, 2003, 08:27 PM
#8
HTREEITEM hRootItem, hNextItem;
hRootItem = m_tree.GetNextItem(hRootItem,TVGN_ROOT);
m_list.AddString(m_tree.GetItemText(hRootItem));
while (true){
hNextItem = m_tree.GetNextItem(hRootItem, TVGN_NEXTVISIBLE );
m_list.AddString(m_tree.GetItemText(hNextItem));
if (!hNextItem)
break;
}
-
October 23rd, 2003, 12:07 AM
#9
K I got it semi working now:
Code:
void CHlmp3ListDlg::OnCreate()
{
m_list.ResetContent();
HTREEITEM hRootItem=NULL, hItem = m_tree.GetNextItem(hRootItem,TVGN_ROOT);
while (hItem != NULL)
{
if (m_tree.GetCheck(hItem)){
m_list.AddString(m_tree.GetItemText(hItem));
}
hItem = m_tree.GetNextItem(hItem,TVGN_NEXTVISIBLE);
}
}
but it will only add the string if the item is checked and it is visiablly expanded.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|