TreeView Control



This Control is used to display the required item or data in hierarchal manner
This is used to save the Design Space
Properties:-

 Nodes:-

This is a Collection property which stores all the group of Nodes within it.Where each node is identified by using its index value .Here Every Node again contains Nodes collection.  


Example


Add a new Form i.e.,FormTreeView to the Windows Application WABasics
Create one TreeView Contril,one Button Control & set the following properties to them

treeView11:
     Name               :         TvSample

button1:

     Name               :         btnCreate

Design :-



 Generate theEventHandler for btnCreate click Event
& write the following code in Source[FormTreeView.cs] 


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 WABasics
{
    public partial class FormTreeView : Form
    {
        public FormTreeView()
        {
            InitializeComponent();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            TVSample.Nodes.Add("Sampath Trust");
            TVSample.Nodes.Add("Private Trust");
            TVSample.Nodes.Add("Govt Trust");
            TVSample.Nodes[0].Nodes.Add("Schools");
            TVSample.Nodes[0].Nodes.Add("Colleges");
            TVSample.Nodes[0].Nodes.Add("Homes");
            TVSample.Nodes[0].Nodes[0].Nodes.Add("Primary School");
            TVSample.Nodes[0].Nodes[0].Nodes.Add("High School");
            TVSample.Nodes[0].Nodes[1].Nodes.Add("Inter College");
            TVSample.Nodes[0].Nodes[1].Nodes.Add("Degree College");
            TVSample.Nodes[0].Nodes[1].Nodes.Add("PG College");
            TVSample.Nodes[0].Nodes[1].Nodes.Add("Engineering College");
            TVSample.Nodes[0].Nodes[2].Nodes.Add("Orphan Homes");
            TVSample.Nodes[0].Nodes[2].Nodes.Add("OldAge Home");
            TVSample.Nodes[0].Nodes[2].Nodes.Add("Peace Home");
        }
    }
}




Result :-


 

No comments:

Post a Comment