Click to See Complete Forum and Search --> : CTreeCtrl, Create node under a childless node
Morrison
September 20th, 2006, 03:33 AM
Hi. I have a strange problem with CtreeCtrl when I whant to create a new node under a node (i will call this node Parent) that have no children.
I create the node from a context menu.
If the node (Parent) have childern, the new node is create under Parent, but If the Parent node have no children nothing happen.
This is my code:
HTREEITEM parent = m_ctlNavigationTree.GetSelectedItem();
HTREEITEM hItem = m_ctlNavigationTree.InsertItem
(
pNENode->GetDisplayText(),
m_icons.GetIconKey(pNENode->GetIcon()),
m_icons.GetIconKey(pNENode->GetIcon()),
parent, TVI_LAST
);
m_ctlNavigationTree.SelectItem(hItem);
Thanks, and sorry for my english.
humptydumpty
September 20th, 2006, 03:55 AM
your Question is not Pretty Much Clear.anyway here is a Sample Example have a look on this may be this one help you.
Thanx
HTREEITEM hItem = m_Tree1.GetSelectedItem();
m_Tree1.GetItemText(hItem,bstr);
//Now Check Whether this Item have Some parent or not.
hParentItem=m_Tree1.GetParentItem(hItem);//get Parent
if (hParentItem==NULL)
{
//means this item Doesn't have any parent it's your root item
//so Insert your new item to this item as Child
}
else
{
//Insert a Item to your parent item
}
Morrison
September 20th, 2006, 04:07 AM
Sorry, my english is not so good.
I will try to explain.
So, I have a CtreeCtrl fill with some data.
for example
Root
-Node1
------ChildNode1
-Node2
------ChildNode2
------ChildNode3
-Node3
OK, Now, I have a context menu,when I make a right Click on a Node a context menu appear with NEW (menu item). When I click New , a new node is created under the node (where I make the right click)
If the node (Node1, where I make the right click) have children, I can see the new node under Node 1.
If the node (Node3) have no children, the new node is not created under the Node3, is not created anywhere.
I hope now you understand my problem.
humptydumpty
September 20th, 2006, 04:17 AM
yes i got your Question and answere is in my above Example just try That hopeFully you Will get the Answer of your Question.of just post your Code(ZIP file) .so easy to Resolve your Problem.
Thanx
Morrison
September 22nd, 2006, 05:50 AM
Hi, I don't fix my problem.
But I discover something.
If I add in my code the following line:
m_ctlNavigationTree.Invalidate()
the new node appear under the Node (parent, with no children).
But on this situation, the node remain selected, and other wird situations.
Can be a problem because I re-implemented the onPaint method for have diffrent colors for nodes?
Please I need help.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.