How do I use mscomctl treeview in C#?

The attached code fails with "Element not Found" message  when I try to create the root node. What arguments do I need with the Nodes.Add function to create a root node?
mscomctl.TreeViewClass treeview = (mscomctl.TreeViewClass)ctrlView.CreateControl("MSComctlLib.TreeCtrl.2");
                    object o = null;
                    object root = "root";
                    object rootTitle = "Root";
                    treeview.Nodes.Add(ref o, ref o, ref root, ref rootTitle, ref o, ref o);

Open in new window

Who is Participating?
Bob LearnedConnect With a Mentor Commented:
You might be able to use a .NET form, and SetParent Win32 API call, to site the form on the ProcessBook user interface.
Bob LearnedCommented:
It is restrictive to use the COM TreeView control in .NET, and C# has a native TreeView control, so I am curious why you need to use the COM version?
MikeInAustraliaAuthor Commented:
Thanks for the reply - I agree that the native treeview is much easier to use but I don't think it is an option in my situation.

I am using a product called Processbook from OSIsoft. It is a graphical tool for viewing process data and it goes back to the early 90's. They provide a  VS2005/2008  C# project template for creating an Addin for the application. Most of what want to achieve is available via the Processbook API but I also need a treeview and the COM version seems like my only option. They provide a Dockable Windows collection that can host Activex controls.  I have attached another code snippet from the Processbook API doc showing the addition of a treeview to their PBControlView object.

If I could get the COM treeview to work the tools for the rest of my task is available in the Application's API. I think my basic problem is that I can't find any docs on the COM treeview control.

Am I doing something obviously wrong in the original code snippett that tries to create the parent node?

Dim cView As PBControlView
Dim oControl As Object
Add the View. This also adds one tab to the window
Set cView = cDockWnd.Views.Add(pbControlView,"My View")
Set oControl = cView.CreateControl("MSComctlLib.TreeCtrl.2")

Open in new window

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Bob LearnedCommented:
You should be able to add a COM ActiveX control to the tool box, and drop a control on to a form, and use early-binding, instead of the late-bound method that it appears you are using.
MikeInAustraliaAuthor Commented:
Not sure if I understand - if I am going to create a .net form I can use the .net treeview and forget the COM treeview but my form will not be part of the ProcessBook user interface. My aim was to put a treeview in the window provided by the Processbook to keep the interface consistent and it seemed a COM component was the only option.  Maybe a separate .net form will save the hassle of the COM component ...
MikeInAustraliaAuthor Commented:
This sounds like it worth a try - thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.