How to create a Tree View in C#

Now we are going to learn about how to create a tree view in C#.
  • 6182

Introduction

In the programming language Tree view is very important and easy concept, designing and coding of the tree view is very simple. Tree view in programming language is used to display text and icons. Programming of the tree view is given below.

Example

using System;
using
System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace tree_view
{
    public partial class Form1 : Form
    {
        public Form1()
       {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {   
    TreeNode treenode = new TreeNode("windows");
            TreeNode nodes1 = new TreeNode("Windows 8");
            TreeNode nodes2 = new TreeNode("Windows 7");
            TreeNode[] arr = new TreeNode[] { nodes1, nodes2 };
            treenode = new TreeNode("Windows", arr);
            treeView1.Nodes.Add(treenode);
            TreeNode nodes3 = new TreeNode("unix");
            TreeNode nodes4 = new TreeNode("linux");
            TreeNode[] arra = new TreeNode[] { nodes3, nodes4 };
            treenode = new TreeNode("oprating system", arra);
            treeView1.Nodes.Add(treenode);
            treenode = new TreeNode("linux");
            TreeNode nodes5 = new TreeNode("ORACAL");
            TreeNode nodes6 = new TreeNode("SQL SERVER");
            TreeNode[] array = new TreeNode[] { nodes5, nodes6 };
            treenode = new TreeNode("Data base", array); 
            treeView1.Nodes.Add(treenode);
            TreeNode nodes7 = new TreeNode("C#");
            TreeNode nodes8 = new TreeNode("vb.net");
            TreeNode[] arraya = new TreeNode[] { nodes7, nodes8 };
            treenode = new TreeNode("dot net language", arraya);
            treeView1.Nodes.Add(treenode);
        }
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
        }    } }

Output

treeview.jpg

© 2013 dotNetheaven. All rights reserved.