Click here to Skip to main content
15,885,546 members
Articles / Programming Languages / Visual Basic

A New .NET Reporting Way

Rate me:
Please Sign up or sign in to vote.
4.67/5 (50 votes)
29 Sep 2007CPOL3 min read 404.6K   17.5K   248  
Looking for a free and simple way to design and add reports to your .NET application? Take a look at MyNeoReport library.
/////////////////////////////////////////////////////////////////////////////////
// MyNeoReport Designer
// --------------------
// Project Copyright (C)    : Fabio Zanetta, email: neofz@interfree.it
// Portions Copyright (C)   : Microsoft Corporation. All Rights Reserved.
// License                  : docs/license.txt
// ------------------------------------------------------------------------------
// File created by          : Fabio Zanetta, email: neofz@interfree.it
// ------------------------------------------------------------------------------
// Please, if you modify some parts of this file mark them as described in
// docs/modify_guidelines.txt
/////////////////////////////////////////////////////////////////////////////////

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

namespace MyNRDesigner.UI
{
	/// <summary>
	/// Descrizione di riepilogo per MyTreeView.
	/// </summary>
    public class MyTreeView : System.Windows.Forms.TreeView 
	{
		/// <summary> 
		/// Variabile di progettazione necessaria.
		/// </summary>
		private System.ComponentModel.Container components = null;
        private List<TreeNode> _selected = new List<TreeNode>();
        public event TreeViewCancelEventHandler ValidateSelect;

		public MyTreeView()
		{
			// Chiamata richiesta da Progettazione form Windows.Forms.
			InitializeComponent();

			// TODO: aggiungere le eventuali istruzioni di inizializzazione dopo la chiamata a InitializeComponent.

		}

		/// <summary> 
		/// Pulire le risorse in uso.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Codice generato da Progettazione componenti
		/// <summary> 
		/// Metodo necessario per il supporto della finestra di progettazione. Non modificare 
		/// il contenuto del metodo con l'editor di codice.
		/// </summary>
		private void InitializeComponent()
		{
			components = new System.ComponentModel.Container();
		}
		#endregion


        private MyTreeNode _GetNode(TreeNodeCollection ns , object item)
        {
            MyTreeNode _node = null;
            foreach (MyTreeNode n in ns)
            {

                if (n.Nodes.Count > 0)
                    _node = _GetNode(n.Nodes, item);

                if (_node == null) 
                {
                    if (n.Item.Equals(item))
                    {
                        return n;
                    }
                } else return _node;
            }
            return null;            
        }
        
        public MyTreeNode GetNode(object item)
        {
            return _GetNode(this.Nodes, item);
        }

        //public new MyTreeNode SelectedNode
        //{
        //    get { return (MyTreeNode)base.SelectedNode; }
        //    set { base.SelectedNode = value; }
        //}

        public void Select(TreeNode node)
        {
            if ((node != null) && (!_selected.Contains(node)))
            {
                node.BackColor = SystemColors.Highlight;
                node.ForeColor = SystemColors.HighlightText;
                _selected.Add(node);
                //this.OnAfterSelect(new TreeViewEventArgs(node));
            }
        }

        public void DeSelect(TreeNode node)
        {
            if (_selected.Contains(node))
            {
                node.BackColor = Color.Transparent;
                node.ForeColor = SystemColors.WindowText;
                _selected.Remove(node);
                //this.OnAfterSelect(new TreeViewEventArgs(node));
            }
        }

        public void DeSelectAll()
        {
            DeselectNode(Nodes[0]);
        }

        public TreeNode[] SelectedNodes
        {
            get { return _selected.ToArray(); }
        }

        void DeselectNode(TreeNode node)
        {

            node.BackColor = Color.Transparent;
            node.ForeColor = SystemColors.WindowText;
            _selected.Remove(node);
            //Console.WriteLine(node.Text);

            foreach (TreeNode n in node.Nodes)
            {
                //n.BackColor = Color.Transparent;
                //n.ForeColor = SystemColors.WindowText;
                //_selected.Remove(n);

                //if (n.Nodes.Count > 0)
                {
                    DeselectNode(n);
                }

            } 
        }

        protected override void OnBeforeSelect(TreeViewCancelEventArgs e)
        {

            SelectedNode = null;

            // this avoid the treeview to process
            // the selection message
            e.Cancel = true;
            base.OnBeforeSelect(e);
            
        }
        

        protected override void OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
        {
            base.OnNodeMouseClick(e);

            if (_selected.Count > 0)
            {
                if ((_selected[0].Level != e.Node.Level) || ((ModifierKeys & Keys.Control) == Keys.None))
                {
                    DeSelectAll();
                    //foreach (TreeNode n in Nodes)
                    //    DeselectNode(n);
                }
            }

            TreeViewCancelEventArgs cea = new TreeViewCancelEventArgs(e.Node, false, TreeViewAction.Unknown);
            if (ValidateSelect != null)
            {                
                ValidateSelect(this, cea);
            }

            if (!cea.Cancel)
            {
                if (_selected.Contains(e.Node))
                {
                    DeSelect(e.Node);
                }
                else
                {
                    Select(e.Node);
                }
            }

            this.OnAfterSelect(new TreeViewEventArgs(e.Node));

        }


	}
}

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
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions