Create treeview programmatically in c#

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
Who is Participating?
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

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

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Anurag ThakurTechnical ManagerCommented:
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
suzan_Author Commented:
thanks ragi0017

I know that but I need to create other tree view
depends on the data that I have
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
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.