Strange CTreeCtrl behavior
-
I have a strange one. I have my own CTreeCtrl for doing multi-select. When build/run a debug version it works just fine. When I build/run a release version, my tree nodes get populated, but I do not see any + on the parent nodes and cannot expand them to see the children. But I can do all that in the debug version without a problem. Any Ideas? :eek: -kg // *** TreeView CMulSelTreeCtrl* pMyTree = (CMulSelTreeCtrl*) GetDlgItem(IDC_TREE1); ASSERT(pMyTree != NULL); pMyTree ->DeleteAllItems(); pMyTree ->ModifyStyle(NULL, TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS); // Associate the image list with the tree control. pMyTree ->SetImageList(pilMyTree, TVSIL_NORMAL); TVINSERTSTRUCT tvInsert; tvInsert.hParent = NULL; tvInsert.hInsertAfter = NULL; tvInsert.item.mask = TVIF_TEXT | TVIF_CHILDREN; // *** TreeView tvInsert.item.pszText = _T(buffer); HTREEITEM hTreeItem = pMyTree ->InsertItem(&tvInsert); Ken Goguen Principle Design Engineer EMC Corporation
-
I have a strange one. I have my own CTreeCtrl for doing multi-select. When build/run a debug version it works just fine. When I build/run a release version, my tree nodes get populated, but I do not see any + on the parent nodes and cannot expand them to see the children. But I can do all that in the debug version without a problem. Any Ideas? :eek: -kg // *** TreeView CMulSelTreeCtrl* pMyTree = (CMulSelTreeCtrl*) GetDlgItem(IDC_TREE1); ASSERT(pMyTree != NULL); pMyTree ->DeleteAllItems(); pMyTree ->ModifyStyle(NULL, TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS); // Associate the image list with the tree control. pMyTree ->SetImageList(pilMyTree, TVSIL_NORMAL); TVINSERTSTRUCT tvInsert; tvInsert.hParent = NULL; tvInsert.hInsertAfter = NULL; tvInsert.item.mask = TVIF_TEXT | TVIF_CHILDREN; // *** TreeView tvInsert.item.pszText = _T(buffer); HTREEITEM hTreeItem = pMyTree ->InsertItem(&tvInsert); Ken Goguen Principle Design Engineer EMC Corporation
Init your structs to zero before using them:
TVINSERTSTRUCT tvInsert = {0};
--Mike-- http://home.inreach.com/mdunn/ Ford: How would you react if I said that I'm not from Guildford after all, but from a small planet somewhere in the vicinity of Betelguese? Arthur: I don't know. Why, do you think it's the sort of thing you're likely to say? -
I have a strange one. I have my own CTreeCtrl for doing multi-select. When build/run a debug version it works just fine. When I build/run a release version, my tree nodes get populated, but I do not see any + on the parent nodes and cannot expand them to see the children. But I can do all that in the debug version without a problem. Any Ideas? :eek: -kg // *** TreeView CMulSelTreeCtrl* pMyTree = (CMulSelTreeCtrl*) GetDlgItem(IDC_TREE1); ASSERT(pMyTree != NULL); pMyTree ->DeleteAllItems(); pMyTree ->ModifyStyle(NULL, TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT | TVS_SHOWSELALWAYS); // Associate the image list with the tree control. pMyTree ->SetImageList(pilMyTree, TVSIL_NORMAL); TVINSERTSTRUCT tvInsert; tvInsert.hParent = NULL; tvInsert.hInsertAfter = NULL; tvInsert.item.mask = TVIF_TEXT | TVIF_CHILDREN; // *** TreeView tvInsert.item.pszText = _T(buffer); HTREEITEM hTreeItem = pMyTree ->InsertItem(&tvInsert); Ken Goguen Principle Design Engineer EMC Corporation
The code you've posted only inserts a root item. And TVIF_CHILDREN flag is ignored during inserts. It works when you're getting information about the item with GetItem. BTW: why are you using a InsertItem overload that takes TVINSERTSTRUCT - there are more convenient versions. Tomasz Sowinski -- http://www.shooltz.com
-
Init your structs to zero before using them:
TVINSERTSTRUCT tvInsert = {0};
--Mike-- http://home.inreach.com/mdunn/ Ford: How would you react if I said that I'm not from Guildford after all, but from a small planet somewhere in the vicinity of Betelguese? Arthur: I don't know. Why, do you think it's the sort of thing you're likely to say?Good practice, but didn't resolve the problem. -kg Ken Goguen Principle Design Engineer EMC Corporation
-
The code you've posted only inserts a root item. And TVIF_CHILDREN flag is ignored during inserts. It works when you're getting information about the item with GetItem. BTW: why are you using a InsertItem overload that takes TVINSERTSTRUCT - there are more convenient versions. Tomasz Sowinski -- http://www.shooltz.com
There is additional code that adds the other nodes, but using message windows I've been able to determine that the expand problem occurs on the first insert. Only using the overload as it was part of an old example I began with. Do you think this could be part of the problem? -kg Ken Goguen Principle Design Engineer EMC Corporation
-
There is additional code that adds the other nodes, but using message windows I've been able to determine that the expand problem occurs on the first insert. Only using the overload as it was part of an old example I began with. Do you think this could be part of the problem? -kg Ken Goguen Principle Design Engineer EMC Corporation
There are many fields in TVITEM struct, which is a member of TVINSERTSTRUCT. You may have overlooked one of them. Give other overloads a try - they are easier to use and understand. Tomasz Sowinski -- http://www.shooltz.com
-
There are many fields in TVITEM struct, which is a member of TVINSERTSTRUCT. You may have overlooked one of them. Give other overloads a try - they are easier to use and understand. Tomasz Sowinski -- http://www.shooltz.com
I simplified as follows and it seems to have done the trick. Thanks. HTREEITEM hTreeItem = pMyTree->InsertItem(_T(buffer),0,0,NULL, TVI_LAST); :-D -kg Ken Goguen Principle Design Engineer EMC Corporation