Learn how to a build a cloud-first strategyRegister Now


How do I use mscomctl treeview in C#?

Posted on 2008-11-04
Medium Priority
Last Modified: 2013-12-17
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

Question by:MikeInAustralia
  • 3
  • 3
LVL 96

Expert Comment

by:Bob Learned
ID: 22886151
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?

Author Comment

ID: 22890052
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

LVL 96

Expert Comment

by:Bob Learned
ID: 22890175
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.
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 22890579
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 ...
LVL 96

Accepted Solution

Bob Learned earned 750 total points
ID: 22890601
You might be able to use a .NET form, and SetParent Win32 API call, to site the form on the ProcessBook user interface.

Author Closing Comment

ID: 31513399
This sounds like it worth a try - thanks

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question