// JP opened flex table

Click to See Complete Forum and Search --> : CTreeView::InsertItem() problem


ColoradoWolf
November 1st, 2000, 05:00 PM
I am running into a problem trying to insert
items in a derived CTreeView class. The code for
my insertion function is as follows:



bool CPIMTreeCtrl::InsertNormalItem(HTREEITEM hParent,
int imgIdx,
CPIMTreeItem* pItem)
{
HTREEITEM hItem = InsertItem(LPSTR_TEXTCALLBACK,imgIdx,imgIdx,
hParent,TVI_SORT);

if (hItem&&pItem->AddHandle(hItem)) {
EnsureVisible(hItem);
SelectItem(hItem);
return(true);
}
else {
return(false);
}
}





The first item I insert using the above function
has no problems. The second node I insert using
this fn (with same hParent) flags an access
violation in USER32.dll (from a call within
COMCTL32.dll) on the CTreeCtrl::InsertItem()
call. I am using VC++ 6 SP4 (MFC4.2) on Win2K.
Has anyone else seen this? Does the parent get
modified and need to be stored again after
inserting a child? Is this just a VC++ bug? Any
info would be appreciated. Thanks.

CW

vdo
November 1st, 2000, 05:18 PM
Well, for my part I can't see any problem with that code. But, you should check the callback function you are using to set the item's text.

ColoradoWolf
November 1st, 2000, 07:00 PM
Thanks for the tip. You were right about the
callback fn. My bad. I modified the fn to look
like this:



bool CPIMTreeCtrl::InsertNormalItem(HTREEITEM hParent,
int imgIdx,
CPIMTreeItem* pItem)
{
if (!pItem||!pItem->GetPIMNode()) {
return(false);
}

HTREEITEM hItem = InsertItem(TVIF_TEXT|TVIF_IMAGE|
TVIF_SELECTEDIMAGE|TVIF_PARAM,
LPSTR_TEXTCALLBACK,
imgIdx,imgIdx,0,0,
(LPARAM)const_cast<CPIMBase*>(pItem->GetPIMNode()),
hParent,TVI_SORT);

if (hItem&&pItem->AddHandle(hItem)) {
EnsureVisible(hItem);
SelectItem(hItem);
return(true);
}
else {
return(false);
}
}





Sending the lparam member gives me the text for the callback. Thanks again. Time for some more coffee.

CW

//JP added flex table