Click here to Skip to main content
15,881,173 members
Articles / Programming Languages / C#

Horizontal Tree Control

Rate me:
Please Sign up or sign in to vote.
4.57/5 (7 votes)
12 Jan 2008CPOL5 min read 78.2K   1.2K   94  
A Vista Explorer like implementation of a control that represents hierachical data.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Demo.DataSet;
using Sarafian.Framework.ClientSide.UI.Resources.HorizontalTree.Nodes;

namespace Demo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        DsTest ds = new DsTest();
        private void Form1_Load(object sender, EventArgs e)
        {
            DsTest.FolderRow row = ds.Folder.NewFolderRow();
            row.Name = "Root";
            row.ParentID = -1;
            ds.Folder.Rows.Add(row);
            for (int i = 1; i < 5; i++)
            {
                DsTest.FolderRow l1 = ds.Folder.AddFolderRow("FolderL1_" + i.ToString(), row);
                for (int j = 1; j < 5; j++)
                {
                    DsTest.FolderRow l2 = ds.Folder.AddFolderRow("FolderL2_" + j.ToString(), l1);
                    for (int k = 1; k < 2; k++)
                    {
                        DsTest.FolderRow l3 = ds.Folder.AddFolderRow("FolderL3_" + k.ToString(), l2);
                    }
                }
            }
            this.horizontalTreeControl1.LinksNode.Suspend();
            this.horizontalTreeControl1.LinksNode.AddNode("Link1", Properties.Resources.Link1, null);
            this.horizontalTreeControl1.LinksNode.AddSeperator();
            this.horizontalTreeControl1.LinksNode.AddNode("Link2", Properties.Resources.Link2, null);
            Node n = new Node();
            this.horizontalTreeControl1.LinksNode.Resume();

            n = new Node();
            n.DisplayText = ds.Folder[0].Name;
            n.Tag = ds.Folder[0];
            n.Image = Properties.Resources.Root;
            
            this.horizontalTreeControl1.NodeActivated += new Sarafian.Framework.ClientSide.UI.Resources.HorizontalTree.DelegateEnum.DelegateNodeActivated(horizontalTreeControl1_NodeActivated);
            this.horizontalTreeControl1.RootNode = n;
        }

        void horizontalTreeControl1_NodeActivated(Node node)
        {
            if (node.Tag is DataRow)
            {
                node.ClearNodes();
                DsTest.FolderRow row = (DsTest.FolderRow)node.Tag;
                node.Suspend();
                foreach (DsTest.FolderRow subRow in row.GetChildRows(this.ds.Folder.ChildRelations[0]))
                {
                    node.AddNode(subRow.Name, Properties.Resources.Folder, subRow);
                }
                node.Resume();
            }
            else
            {
                //MessageBox.Show(node.DisplayText);
            }

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader ALGOSYSTEMS
Greece Greece
I live in Athens Greece and currently I am working with Business scale application with .NET latest technologies

I've been developing applications for personal and friends usage with C++ using majorly Borland's various IDEs since 1994.
In 2002 I began working for an R&D institute where I was introduced to C# which I worships ever since.

I love core application development and I would like to publish more articles here and on my blog, but there is not enough time to do so.

I usualy "waste" my spare time watching sitcoms, preferable SCI-FI.
I would like to play chess but I can't find any real world players to hang out with.

Comments and Discussions