TreeView Demo : TreeView « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » GUI Windows Form » TreeView 




TreeView Demo
TreeView Demo

/*
Professional Windows GUI Programming Using C#
by Jay Glynn, Csaba Torok, Richard Conway, Wahid Choudhury, 
   Zach Greenvoss, Shripad Kulkarni, Neil Whitlow

Publisher: Peer Information
ISBN: 1861007663
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TreeView
{
  /// <summary>
  /// Summary description for TreeViewDemo.
  /// </summary>
  public class TreeViewDemo : System.Windows.Forms.Form
  {
    private System.Windows.Forms.TreeView treeView1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;
    ImageList il = new ImageList();
    public TreeViewDemo()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Disposebool disposing )
    {
      ifdisposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
         this.treeView1 = new System.Windows.Forms.TreeView();
         this.SuspendLayout();
         // 
         // treeView1
         // 
         this.treeView1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom
            | System.Windows.Forms.AnchorStyles.Left
            | System.Windows.Forms.AnchorStyles.Right);
         this.treeView1.Font = new System.Drawing.Font("Courier New"12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
         this.treeView1.HotTracking = true;
         this.treeView1.ImageIndex = -1;
         this.treeView1.Indent = 30;
         this.treeView1.ItemHeight = 30;
         this.treeView1.LabelEdit = true;
         this.treeView1.Location = new System.Drawing.Point(816);
         this.treeView1.Name = "treeView1";
         this.treeView1.SelectedImageIndex = -1;
         this.treeView1.Size = new System.Drawing.Size(360272);
         this.treeView1.TabIndex = 0;
         // 
         // TreeViewDemo
         // 
         this.AutoScaleBaseSize = new System.Drawing.Size(513);
         this.ClientSize = new System.Drawing.Size(376309);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.treeView1});
         this.Name = "TreeViewDemo";
         this.Text = "TreeView Control";
         this.Load += new System.EventHandler(this.TreeViewDemo_Load);
         this.ResumeLayout(false);

      }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new TreeViewDemo());
    }

    private void TreeViewDemo_Load(object sender, System.EventArgs e)
    {
      // Select icons into the image list
      il.Images.Add(new Icon("KEY04.ICO"));
      il.Images.Add(new Icon("ARW06LT.ICO"));
      il.Images.Add(new Icon("LITENING.ICO"));
      il.Images.Add(new Icon("ARW06UP.ICO"));
      treeView1.ImageList = il ; 
  
      // Create the RootNode
      TreeNode rootNode = treeView1.Nodes.Add("USA");
      rootNode.ImageIndex =;

      // Create the Child nodes for the root
      TreeNode states1 = rootNode.Nodes.Add("New York");
      states1.ImageIndex =;
      TreeNode states2 = rootNode.Nodes.Add("Michigan");
      states2.ImageIndex =;
      TreeNode states3 = rootNode.Nodes.Add("Wisconsin");
      states3.ImageIndex =;
      TreeNode states4 = rootNode.Nodes.Add("California");
      states4.ImageIndex =;

      // Create siblings nodes for the Child nodes 
      TreeNode child = states1.Nodes.Add("Rochester");
      child.ImageIndex = ;
      child =states1.Nodes.Add("new York");
      child.ImageIndex = ;
      child =states1.Nodes.Add("Albany");
      child.ImageIndex = ;

      child = states2.Nodes.Add("Detroit");
      child.ImageIndex = ;
      child =states2.Nodes.Add("Ann Arbor");
      child.ImageIndex = ;
      child =states2.Nodes.Add("Lansing");
      child.ImageIndex = ;

      child = states3.Nodes.Add("Milwaukee");
      child.ImageIndex = ;
      child =states3.Nodes.Add("Madison");
      child.ImageIndex = ;
      child =states3.Nodes.Add("La Cross");
      child.ImageIndex = ;
    
      child = states4.Nodes.Add("Los Angeles");
      child.ImageIndex = ;
      child =states4.Nodes.Add("San Fransisco");
      child.ImageIndex = ;
      child =states4.Nodes.Add("San Diego");
      child.ImageIndex = ;
    }
  }
}


           
       














TreeView.zip( 32 k)
Related examples in the same category
1.Recursively load Directory info into TreeViewRecursively load Directory info into TreeView
2.Drag and drop Tree NodeDrag and drop Tree Node
3.Get Selected Node Full PathGet Selected Node Full Path
4.Custom TreeView
5.TreeView ExampleTreeView Example
6.TreeView Drag And DropTreeView Drag And Drop
7.TreeView Data BindingTreeView Data Binding
8.Read an XML Document and display the file as a TreeRead an XML Document and display the file as a Tree
9.Directory Tree HostDirectory Tree Host
10.Subclass TreeView
11.Add Nodes to TreeView
12.TreeView ImageIndex
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.