Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to add a child item in Tree Ctrl?

86 views
Skip to first unread message

mizi

unread,
Nov 27, 2000, 3:00:00 AM11/27/00
to
I use CTreeCtrl::InsertItem("text", hParentItem),
but it seems that the item wasn't inserted,the parent item
still hasn't child item,why?

Andy Hassall

unread,
Nov 28, 2000, 3:00:00 AM11/28/00
to

Are you sure hParentItem is a valid tree item handle of an item already
inserted?

Have you redrawn the tree control?

--
Andy Hassall (an...@andyh.org) icq(5747695) http://www.andyh.org
http://www.andyh.uklinux.net/space - disk usage analysis tool

Dieter Hammann

unread,
Dec 15, 2000, 12:23:12 PM12/15/00
to
In article <Xns8FFA6D1E5...@207.46.180.24>,

ope...@yeah.net (mizi) wrote:
> I use CTreeCtrl::InsertItem("text", hParentItem),
> but it seems that the item wasn't inserted,the parent item
> still hasn't child item,why?
>

I get a similar problem using CTreeCtrl::InsertItem(LPTVINSERTSTRUCT):
When inserting two items using this function (a parent and a child
item), the child is not displayed (although a valid handle is returned)
and the parent seems to be childless.
(Environment: VC++6, W2K SP1)

When using the overload function CTreeCtrl::InsertItem(UINT nMask,
LPCTSTR lpszItem, ...) everything works just fine.

I worked around this problem by setting the parent's children flag
manually after inserting a child item:

TVITEM tvitem;
memset(&tvitem, 0, sizeof(TVITEM));
tvitem.hItem = hParentItem;
tvitem.mask = TVIF_CHILDREN;
tvitem.cChildren = 1;
m_tree.SetItem(&tvitem);

It's also possible to set cChildren in each item's TVITEM structure to
I_CHILDRENCALLBACK, but then you will have to handle the
TVN_GETDISPINFO message to tell the tree control if an item has
children or not. If you don't handle the message, the item will appear
to have children even if it's childless, but you can't expand the
branch.


Sent via Deja.com
http://www.deja.com/

0 new messages