CTreeCtrl problem in MFC
-
The function
ItemHasChildren (TreeItem)
returns true for a perticular node butGetChildItem (TreeItem)
doesnot return a valid node without expanding the nodeTreeItem
. This expanding and shrinking is causing flicker in the tree. Could anyone provide a better solution ? The sample code is following -if (ItemHasChildren (TreeItem)) { HTREEITEM tmpTreeItem = TreeItem; Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker TreeItem = GetChildItem (TreeItem); Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker }
-
The function
ItemHasChildren (TreeItem)
returns true for a perticular node butGetChildItem (TreeItem)
doesnot return a valid node without expanding the nodeTreeItem
. This expanding and shrinking is causing flicker in the tree. Could anyone provide a better solution ? The sample code is following -if (ItemHasChildren (TreeItem)) { HTREEITEM tmpTreeItem = TreeItem; Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker TreeItem = GetChildItem (TreeItem); Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker }
NishantB++ wrote:
expanding and shrinking is causing flicker in the tree.
Stop the tree from redrawing while you are tampering with it. From my CTreeView I do:
GetTreeCtrl().SetRedraw( FALSE); ... GetTreeCtrl().SetRedraw( TRUE);
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency" -
NishantB++ wrote:
expanding and shrinking is causing flicker in the tree.
Stop the tree from redrawing while you are tampering with it. From my CTreeView I do:
GetTreeCtrl().SetRedraw( FALSE); ... GetTreeCtrl().SetRedraw( TRUE);
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency" -
Thanks for your reply. I have already tried this option, and it is not working. By the way, have you seen this kind of behaviour that you have to expand the tree first to get the child node, or I am doing something wrong?
NishantB++ wrote:
expand the tree first to get the child node
I have. But then I use CWaitingTreeCtrl from Codeproject[^], and there things are much more complicated. It might really be that the item does not know that it has children and how many of them.
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
Douglas Adams, "Dirk Gently's Holistic Detective Agency" -
The function
ItemHasChildren (TreeItem)
returns true for a perticular node butGetChildItem (TreeItem)
doesnot return a valid node without expanding the nodeTreeItem
. This expanding and shrinking is causing flicker in the tree. Could anyone provide a better solution ? The sample code is following -if (ItemHasChildren (TreeItem)) { HTREEITEM tmpTreeItem = TreeItem; Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker TreeItem = GetChildItem (TreeItem); Expand (tmpTreeItem, TVE\_TOGGLE); //Causing flicker }
The below code is from MSDN. While their samples can be lacking sometimes, they're not usually wrong.
if (pmyTreeCtrl->ItemHasChildren(hmyItem))
{
HTREEITEM hNextItem;
HTREEITEM hChildItem = pmyTreeCtrl->GetChildItem(hmyItem);while (hChildItem != NULL)
{
hNextItem = pmyTreeCtrl->GetNextItem(hChildItem, TVGN_NEXT);
pmyTreeCtrl->DeleteItem(hChildItem);
hChildItem = hNextItem;
}
}The only thing I can think of that may mess it up is if your parent item does not actually have children in it, but you've manually set its item.cChildren to I_CHILDRENCALLBACK. Can you check the return value from ItemHasChildren to make sure it's 0 or 1? Iain.