Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with "CTreeCtrl::Expand()" function....

Status
Not open for further replies.

qednick

Programmer
Jul 26, 2002
516
US
Hi all, I'm having real difficulties getting the Expand() function to work with my tree control. Funny thing is, the problem only occurs when I want to expand the item (collapsing works great!).

Here's the code I'm using:

// This works great!
theTree->Expand(theTreeItem,TVE_COLLAPSE);

// but when it comes to expanding the very same
// HTREEITEM item, this doesn't work
theTree->Expand(theTreeItem,TVE_EXPAND);

Has anybody else noticed this? Could this be a bug in VC++?
Any comments would be welcome.

Thanks
 

Make sure you are not re-initializing your tree handle so that is doesn't point to the right tree. For example:

// get control
CTreeCtrl& TreeCtrl = GetTreeCtrl();

HTREEITEM MyFineTree;

MyFineTree = TreeCtrl.InsertItem("One Fine Tree");
TreeCtrl.InsertItem("testing0",MyFineTree,TVI_LAST);
TreeCtrl.InsertItem("testing1",MyFineTree,TVI_LAST);
TreeCtrl.Expand(MyFineTree, TVE_EXPAND );

The above code will work. No bugs. But if you do this in another memeber function:

HTREEITEM MyFineTree;
TreeCtrl.Expand(MyFineTree, TVE_EXPAND );

The code will run without errors but the tree will not expand.

Brother C
 
Thx Brother C but here's the scenario now....

I've now changed things a little and am using the Tree Control member variable directly (no pointers, references, etc).

I have a combo box item above the tree. The user can choose an item from the combo box and, upon doing so, the contents of the tree change.

Now... here's my sticking point: Upon changing the tree items, I want all the items in the tree to collapse except the very first item in the list.

Everything is working perfectly except for the Expand() function.

??????????????????????/
 
OK.. I got it.....

this is what I used:

m_Tree.Expand(m_Tree.GetFirstVisibleItem(),TVE_EXPAND);


Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top