Create treeview programmatically in c#

Posted on 2008-11-15
Medium Priority
Last Modified: 2013-12-17
Could someone please help me with this
I know that I should insert a treeview from the toolbox in the design page in order to Create treeview.
Is there is a way i could do it programmatically in c#

Thanks in advance
Question by:suzan_
LVL 13

Expert Comment

ID: 22969986

Author Comment

ID: 22971982
thanks TechTiger007 for your help
but I need to create the treeview in run time not dynamically

LVL 26

Expert Comment

by:Anurag Thakur
ID: 22973331
tree view control once place can be created at run time - means the data can be added at run time
have a look at the following sample
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 22973417
thanks ragi0017

I know that but I need to create other tree view
depends on the data that I have

Accepted Solution

torrie01 earned 2000 total points
ID: 22978673
Hi Suzan,

Are you looking for a way to simply add a new treeview control to your form?  If so, do something like this:
TreeView myTreeView = new TreeView();
myTreeView.Location = new Point(0,0);
myTreeView.Size = new Size(100,200);
//now that it's on the form, you can add nodes to it
myTreeView.Nodes.Add(new TreeNode("something");

Open in new window

LVL 13

Expert Comment

ID: 22985939
Hi Suzan,
The sample that I pointed out from msdn is creating a treeview during runtime and adding it to the page.

When you meant "during runtime" I understood that you wanted to create a tree view control based on some data create nodes and add this control to the page. This is what is done in the code. Correct me if I am  wrong

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 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