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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

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

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.
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

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 ...
Bob LearnedCommented:
You might be able to use a .NET form, and SetParent Win32 API call, to site the form on the ProcessBook user interface.

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
MikeInAustraliaAuthor Commented:
This sounds like it worth a try - thanks
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
.NET Programming

From novice to tech pro — start learning today.