Microsoft TreeView ActiveX control version 6.0

I must write a simple demo which demonstrates the use of this control. I couldn't find any documentation in MSDN.

The following would be enough:

Add 5 items (strings) to the TreeView ActiveX control.

Thanks
LVL 2
MindoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fstabCommented:
Use this code :

TV_INSERTSTRUCT tvinsert;
HTREEITEM *hParents;

CTreeCtrl &pTree = GetTreeCtrl();

tvinsert.hParent = NULL;
tvinsert.hInsertAfter = TVI_LAST;
tvinsert.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;
tvinsert.item.hItem = NULL;
tvinsert.item.state = 0;
tvinsert.item.stateMask = 0;
tvinsert.item.cchTextMax = 6;
tvinsert.item.iSelectedImage = 1;
tvinsert.item.cChildren = 0;
tvinsert.item.lParam = 0;

hParents = new HTREEITEM[rootdircount];
char parent[512];
memset(parent,0,512);
tvinsert.item.pszText = "Your text";
hParents[count] = pTree.InsertItem(&tvinsert);

for(int i=0;i<5;i++) {
tvinsert.hParent = h;
lstrcpy(tvinsert.item.pszText, "Child text" );
HTREEITEM newhandle = pTree.InsertItem(&tv);
}
delete hParents;
return TRUE;


Let me know if it works ..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fstabCommented:
I forgot to add that please substitute your own variables in places where you find undefined variables - in other words, I've pasted some code from one of my own apps so you might find some of them ..
0
MindoAuthor Commented:
My tree control doesn't have a GetTreeCtrl() method. This is what my compiler says.

So the following code doesn't work for me:

m_tree.GetTreeCtrl();

// m_tree is an instance of CTreeView

I'm using the Microsoft TreeView ActiveX control version 6.0. It's not an MFC CTreeView class. Although i think it's made using this class.

Can you help me?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

fstabCommented:
OK .. here's what you probably have - you must be having a Treeview control on your dialog. If yes, please do the following :

Open Classwizard in your project, switch the tab to Member variables. Click on the Treeview control ID, and add a variable m_Tree.

Also remove all references to GetTreeCtrl in the code which I gave you and recompile.

If you're trying to create a TreeView control on the "fly" in code, I'd advise you to go with my approach - which is add a TreeView control to your dialog box using the Dialog editor in Visual Studio.

Let me know what happens ..
fstab.
0
MindoAuthor Commented:
I've added a member variable for my dialog already. In y previous comment i've pasted the following:

m_tree.GetTreeCtrl();

the m_tree is my member variable of the TreeView ActiveX control.

And it says there's no such method :-(
0
fstabCommented:
Please remove this method of m_Tree which you're trying to call .. it is not required.
0
MindoAuthor Commented:
Hmm,

What do you mean by saying to remove the method i'm trying to call?

I need this method to add items to the TreeView. How to add the items? To get the tree by GetCtrlTree() and add items to it. Is there any other way?

But as i told you before this method doesn't work for me.

0
fstabCommented:
I meant to say that you don't need the GetTreeCtrl method to get a reference to the Tree control, since you've already added it as a variable from Classwizard.

Please see the code which I've pasted in my proposed answer, leaving out the line where it calls GetTreeCtrl.

Instead of using pTree in my code use m_Tree.

GetTreeCtrl, FYI is only to be used from a CTreeView object inorder to get a reference to the underlying Tree control.

Hope that makes things clear - if not, please show me your code and we'll take it from there.
0
fstabCommented:
I meant to say that you don't need the GetTreeCtrl method to get a reference to the Tree control, since you've already added it as a variable from Classwizard.

Please see the code which I've pasted in my proposed answer, leaving out the line where it calls GetTreeCtrl.

Instead of using pTree in my code use m_Tree.

GetTreeCtrl, FYI is only to be used from a CTreeView object inorder to get a reference to the underlying Tree control.

Hope that makes things clear - if not, please show me your code and we'll take it from there.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.