|
-
May 26th, 1999, 04:19 AM
#1
Help with CTreeCtrl.SetItemData()
I have some prob with CTreeCtrl.SetItemData()
I do this in OnInitialUpdate of my CTreeView class
int IDPersonne;
hItemData = ctc.InsertItem("Info",NULL,NULL, hSubTreeDirection);
bool bok = ctc.SetItemData(hItemData,IDPersonne);
DWORD dw = ctc.GetItemData(hItemData);
my variable dw has the correct number.
But in my OnDblclk() function
I Do this
CTreeCtrl &ctc = GetTreeCtrl();
HTREEITEM hTreeItem = ctc.GetParentItem(ctc.GetSelectedItem());
if (hTreeItem != NULL)
{
AfxMessageBox(ctc.GetItemText(hTreeItem));
DWORD dw = ctc.GetItemData(hTreeItem);
}
and there the dw value is 0 ??
What I wrong
Christian Niquille
Thanks for your help
-
May 26th, 1999, 05:07 AM
#2
Re: Help with CTreeCtrl.SetItemData()
When you use SetItemData(...),you pass a auto variable to this function,It's wrong.
you can do like this:
static INT IDPersonne;
...
ctc.SetItemData(hItemData,IDPersonne);
//Or you can do it like this.
int *IDPersonne=new INT;
...
ctc.SetItemData(hItemData,*IDPersonne);
...
//now everything is OK.
-
May 26th, 1999, 09:22 AM
#3
Re: Help with CTreeCtrl.SetItemData()
The scope of IDPersonne is not the problem. SetItemData() for any control which supports it stores a COPY of the data passed in the control's own memory space, so it does not matter if the original variable passed goes out of scope.
-
May 26th, 1999, 09:28 AM
#4
Re: Help with CTreeCtrl.SetItemData()
The only thing I can think of is that the branch of the tree that you are retrieving is NOT the one you stored the data in.
To (dis)prove this, when you call SetItemData() in OnInitialUpdate(), make a note of the value of hItemData. Then, in the OnDblclk() routine, check the value of hTreeItem and make sure it is the same. If it is, and the value retrieved is not the same, then I can only think that something you are doing in between is corrupting the branch's data.
Perhaps the full code for the tree view class would help us to see something?
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
|