TreeView Example : 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.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » TreeViewScreenshots 
TreeView Example
TreeView Example

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TreeViewExample
{
    /// <summary>
    /// Summary description for TreeViewExample.
    /// </summary>
    public class TreeViewExample : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.TreeView treeFood;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public TreeViewExample()
        {
            //
            // 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.treeFood = new System.Windows.Forms.TreeView();
            this.SuspendLayout();
            // 
            // treeFood
            // 
            this.treeFood.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom
                | System.Windows.Forms.AnchorStyles.Left
                | System.Windows.Forms.AnchorStyles.Right);
            this.treeFood.ImageIndex = -1;
            this.treeFood.Location = new System.Drawing.Point(45);
            this.treeFood.Name = "treeFood";
            this.treeFood.SelectedImageIndex = -1;
            this.treeFood.Size = new System.Drawing.Size(284256);
            this.treeFood.TabIndex = 1;
            this.treeFood.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeFood_AfterSelect);
            // 
            // TreeViewExample
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(513);
            this.ClientSize = new System.Drawing.Size(292266);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.treeFood});
            this.Name = "TreeViewExample";
            this.Text = "TreeView Example";
            this.Load += new System.EventHandler(this.TreeViewExample_Load);
            this.ResumeLayout(false);

        }
        #endregion

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

        private void TreeViewExample_Load(object sender, System.EventArgs e)
        {
            TreeNode node;
            
            node = treeFood.Nodes.Add("Fruits");
            node.Nodes.Add("Apple");
            node.Nodes.Add("Peach");
            
            node = treeFood.Nodes.Add("Vegetables");
            node.Nodes.Add("Tomato");
            node.Nodes.Add("Eggplant");
        }

        private void treeFood_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
        {
            if (e.Action == TreeViewAction.ByMouse)
            {
                MessageBox.Show(e.Node.FullPath);
            }
        }
    }
}


           
       
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 Drag And DropTreeView Drag And Drop
6.TreeView Data BindingTreeView Data Binding
7.Read an XML Document and display the file as a TreeRead an XML Document and display the file as a Tree
8.TreeView DemoTreeView Demo
9.Directory Tree HostDirectory Tree Host
10.Subclass TreeView
11.Add Nodes to TreeView
12.TreeView ImageIndex
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.