WHAT IS BASIC CONCEPT FOR TREE VIEW

Mark Devid

Total Post:9

Points:45
Posted by  Mark Devid
C# 
C#
 255  View(s)
Ratings:
Rate this:
  1. Mark Devid

    Post:9

    Points:45
    What is basic concept for tree view

    Basic Concept for Tree View 

     

    TreeNode is the keyword which is used to represent the node for the Treeview.

     

    We need to define the name for the TreeNode

     

    eg ;- TreeNode Node1

     

    How to add 1st element in the node :

     

    syntax  tNode = treeView1.Nodes.Add("Country");

     

    treeView1 is the name of the Tree view which is present in your form




    Now, we can add many node to this  node.

     

    eg. treeView1.Nodes[0].Nodes.Add("India");

     

            we can add many node to 2nd node       

    eg treeView1.Nodes[0].Nodes[0].Nodes.Add("Delhi");

     

    Here is the complete code we can implement in our coding

     

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using System.Windows.Forms;

     

    namespace WindowsFormsApplication18

    {

        public partial class Form1 : Form

        {

            public Form1()

            {

                InitializeComponent();

            }

     

            private void Form1_Load(object sender, EventArgs e)

            {

                TreeNode node1,tNode;

     

                tNode = treeView1.Nodes.Add("Country");

     

                treeView1.Nodes[0].Nodes.Add("India");

                treeView1.Nodes[0].Nodes[0].Nodes.Add("Delhi");

     

                treeView1.Nodes[0].Nodes.Add("Australia");

                treeView1.Nodes[0].Nodes[1].Nodes.Add("Canberra");

                treeView1.Nodes[0].Nodes[1].Nodes.Add("Perth");

     

                treeView1.Nodes[0].Nodes.Add("NewZealand");

                treeView1.Nodes[0].Nodes[2].Nodes.Add("Auckland");

                treeView1.Nodes[0].Nodes[2].Nodes[0].Nodes.Add("North_land");

            }

            private void button1_Click(object sender, EventArgs e)

            {

                MessageBox.Show(treeView1.SelectedNode.FullPath.ToString());

            }

        }

    }

     

      Modified On Sep-16-2016 01:18:49 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!