Menu

Hiding the extra column

2015-10-01
2015-10-09
  • Andrew Ellis

    Andrew Ellis - 2015-10-01

    Hi

    I have added the advanced treeview to my application, and have created a table with 2 columns. Everything works really well, and I'm very pleased with the control.

    The issue I have is that there is a third column present which I cannot reference. Is there a way to hide the third column?

    Andrew

     
    • Lee

      Lee - 2015-10-06

      Hi,
      Add an example and an image depicting the issue, so it'll be easier to help you.

       
  • Andrew Ellis

    Andrew Ellis - 2015-10-07

    Hi Lee,

    Thanks for getting back to me. I have attached a picture to clarify the issue. The area in yellow is what I want to get rid of.

    I have pasted my code at the bottom of the message.

    Andrew

    MainForm.cs

    /*
     * Created by SharpDevelop.
     * User: Andrew
     * Date: 16/09/2015
     * Time: 11:42
     * 
     * To change this template use Tools | Options | Coding | Edit Standard Headers.
     */
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;
    using Aga.Controls.Tree;
    using Aga.Controls.Tree.NodeControls;
    using Aga.Controls;
    
    namespace TestApplication
    {       
        /// <summary>
        /// Description of MainForm.
        /// </summary>
        public partial class MainForm : Form
        {
    
            private class ToolTipProvider : IToolTipProvider
            {
                public string GetToolTip(TreeNodeAdv node, NodeControl nodeControl)
                {
                    return "Drag&Drop nodes to move them";
                }
            }
    
            private TreeModel _model;
            private Font _childFont;
    
            private int count = 0;
    
            MetaDisplayModel meta_model;
    
            List <MetaItems> root_items;
    
            List <MetaItems> _metadata;
    
            public MainForm()
            {
                //
                // The InitializeComponent() call is required for Windows Forms designer support.
                //
                InitializeComponent();
    
                _name.ToolTipProvider = new ToolTipProvider();
                _value.ToolTipProvider = new ToolTipProvider();
                _model = new TreeModel();
                _childFont = new Font(_tree.Font.FontFamily, 18, FontStyle.Bold);
    
                meta_model = new MetaDisplayModel();
    
                _tree.Model = new SortedTreeModel(meta_model);          
    
                timer1.Start();
    
                root_items = meta_model._RootItems;
    
            }
    
            void Timer1Tick(object sender, EventArgs e)
            {                       
                count++;
    
                try
                {               
                    _metadata = meta_model._itemsDisplayed;
                    _metadata[0].Value = count * 10;
                    _metadata[1].Value = count;
    
                    _tree.Invalidate();
                }
    
                catch (Exception ex)
                {
    
                }
            }
            void Button1Click(object sender, EventArgs e)
            {
                try
                {
                    _metadata.Add(new MetaData("Test", _metadata[0].Parent, _metadata[0].Owner));
    
                    meta_model.Refresh();                       
                }
    
                catch (Exception ex)
                {
    
                }
    
            }
    
        }
    }
    

    MetaItems.cs

    /*
     * Created by SharpDevelop.
     * User: Andrew
     * Date: 29/09/2015
     * Time: 09:57
     * 
     * To change this template use Tools | Options | Coding | Edit Standard Headers.
     */
    using System;
    using Aga.Controls.Tree;
    using Aga.Controls.Tree.NodeControls;
    using Aga.Controls;
    
    namespace TestApplication
    {
        /// <summary>
        /// Description of MetaItems.
        /// </summary>
        public abstract class MetaItems
        {   
            string _name;       
            public string ItemName
            {
                get { return _name; }
                set { _name = value; }
            }
    
            string _value;
            public string ItemValue
            {
                get; //{ return _value; }
                set;// { _value = value; }
            }   
    
            private MetaItems _parent;
            public MetaItems Parent
            {
                get { return _parent; }
                set { _parent = value; }
            }
    
            public abstract string Name
            {
                get;
                set;
            }
    
            public abstract int Value
            {
                get;
                set;            
            }
    
            private MetaDisplayModel _owner;
            public MetaDisplayModel Owner
            {
                get { return _owner; }
                set { _owner = value; }
            }
        }
    
        public class RootItem : MetaItems
        {
            public RootItem(string name, MetaDisplayModel owner)
            {
                ItemName = name;            
                Owner = owner;
            }
    
            public override string Name
            {
                get
                {
                    return ItemName;
                }
                set
                {
                }
            }
    
            public override int Value
            {
                get; //{ return _value; }
                set;// { _value = value; }
            }   
        }
    
        public class MetaData : MetaItems
        {
            public MetaData(string name, MetaItems parent, MetaDisplayModel owner)
            {
                ItemName = name;
                Parent = parent;
                Owner = owner;
            }
    
            public override string Name
            {
                get
                {
                    return ItemName;
                }
                set
                {
    
                }
            }
    
            public override int Value
            {
                get { return Convert.ToInt32(ItemValue); }
                set { ItemValue = value.ToString(); }
            }
    
        }   
    }
    

    MetaDisplayModel.cs

    /*
     * Created by SharpDevelop.
     * User: Andrew
     * Date: 29/09/2015
     * Time: 11:20
     * 
     * To change this template use Tools | Options | Coding | Edit Standard Headers.
     */
    using System;
    using System.IO;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Windows.Forms;
    using Aga.Controls.Tree;
    using Aga.Controls.Tree.NodeControls;
    using Aga.Controls;
    
    namespace TestApplication
    {
        /// <summary>
        /// Description of MetaDisplayModel.
        /// </summary>
        public class MetaDisplayModel: ITreeModel
        {
            public List<MetaItems> _itemsToDisplay;
            private Dictionary<string, List<MetaItems>> _cache = new Dictionary<string, List<MetaItems>>();
    
            public List<MetaItems> _itemsDisplayed
            {
                get
                {
                    return _cache["Metadata set"];
                }
    
                set
                {
                    _cache["Metadata set"] = _itemsDisplayed;
                }
    
            }
    
            public List<MetaItems> _RootItems
            {
                get
                {
                    return _cache["ROOT"];
                }
    
                set
                {
                    //_cache["ROOT"] = _itemsDisplayed;
                }
    
            }
    
            public MetaDisplayModel()
            {
                _itemsToDisplay = new List<MetaItems>();    
    
            }
    
            private TreePath GetPath(MetaItems item)
            {
                if (item == null)
                    return TreePath.Empty;
                else
                {
                    Stack<object> stack = new Stack<object>();
                    while (item != null)
                    {
                        stack.Push(item);
                        item = item.Parent;
                    }
                    return new TreePath(stack.ToArray());
                }
            }
    
            public System.Collections.IEnumerable GetChildren(TreePath treePath)
            {
                string[] meta_names = new string[7] {"Meta 1", "Meta 2", "Meta 3", "Meta 4", "Meta 5", "Meta 6", "Meta 7"};
                List<MetaItems> items = null;
                if (treePath.IsEmpty())
                {
                    if (_cache.ContainsKey("ROOT"))
                        items = _cache["ROOT"];
                    else
                    {
                        items = new List<MetaItems>();
                        _cache.Add("ROOT", items);
    
                        items.Add(new RootItem("Metadata blank", this));
                        items.Add(new RootItem("Metadata set", this));
                    }
                }
    
                else
                {
                    MetaItems parent = treePath.LastNode as MetaItems;
                    if (parent != null)
                    {
                        if (_cache.ContainsKey(parent.ItemName))
                            items = _cache[parent.ItemName];
                        else
                        {
                            if (parent.ItemName == "Metadata set")
                            {
                                items = new List<MetaItems>();
                                try
                                {
                                    foreach (string str in meta_names)
                                    {
                                        items.Add(new MetaData(str, parent, this));                                 
                                    }
                                }
                                catch (IOException)
                                {
                                    return null;
                                }
                                _cache.Add(parent.ItemName, items);
                                _itemsToDisplay.AddRange(items);
    
                            }
                        }
                    }
                }
    
                return items;
            }
    
            public bool IsLeaf(TreePath treePath)
            {
                return treePath.LastNode is MetaData;
            }
    
            public event EventHandler<TreeModelEventArgs> NodesChanged;
            internal void OnNodesChanged(MetaItems item)
            {
                if (NodesChanged != null)
                {
                    TreePath path = GetPath(item.Parent);
                    NodesChanged(this, new TreeModelEventArgs(path, new object[] { item }));
                }
            }
    
            public event EventHandler<TreeModelEventArgs> NodesInserted;
            public event EventHandler<TreeModelEventArgs> NodesRemoved;
            public event EventHandler<TreePathEventArgs> StructureChanged;
            public void OnStructureChanged(TreePathEventArgs args)
            {
                if (StructureChanged != null)
                {
                    StructureChanged(this, args);               
                }
            }
    
            public virtual void Refresh()
            {
                OnStructureChanged(new TreePathEventArgs());
            }
    
        }   
    
    }
    
     

    Last edit: Andrew Ellis 2015-10-07
  • Laurent Nicot

    Laurent Nicot - 2015-10-08

    Missing MainForm.Designer.cs file to see how _tree is defined

     
  • Andrew Ellis

    Andrew Ellis - 2015-10-08

    Hi I have pasted MainForm.Designer.cs below.

    Andrew

    /*
     * Created by SharpDevelop.
     * User: Andrew
     * Date: 16/09/2015
     * Time: 11:42
     * 
     * To change this template use Tools | Options | Coding | Edit Standard Headers.
     */
    namespace TestApplication
    {
        partial class MainForm
        {
            /// <summary>
            /// Designer variable used to keep track of non-visual components.
            /// </summary>
            private System.ComponentModel.IContainer components = null;
            private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBox1;
            private Aga.Controls.Tree.NodeControls.NodeTextBox nodeTextBox2;
            private Aga.Controls.Tree.TreeViewAdv _tree;
            private Aga.Controls.Tree.NodeControls.NodeTextBox _name;
            private System.Windows.Forms.Timer timer1;
            private Aga.Controls.Tree.NodeControls.NodeTextBox _value;
            private Aga.Controls.Tree.TreeColumn treeColumn1;
            private Aga.Controls.Tree.TreeColumn treeColumn2;
            private System.Windows.Forms.Button button1;
    
            /// <summary>
            /// Disposes resources used by the form.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing) {
                    if (components != null) {
                        components.Dispose();
                    }
                }
                base.Dispose(disposing);
            }
    
            /// <summary>
            /// This method is required for Windows Forms designer support.
            /// Do not change the method contents inside the source code editor. The Forms designer might
            /// not be able to load this method if it was changed manually.
            /// </summary>
            private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.nodeTextBox1 = new Aga.Controls.Tree.NodeControls.NodeTextBox();
                this.nodeTextBox2 = new Aga.Controls.Tree.NodeControls.NodeTextBox();
                this._tree = new Aga.Controls.Tree.TreeViewAdv();
                this.treeColumn1 = new Aga.Controls.Tree.TreeColumn();
                this.treeColumn2 = new Aga.Controls.Tree.TreeColumn();
                this._name = new Aga.Controls.Tree.NodeControls.NodeTextBox();
                this._value = new Aga.Controls.Tree.NodeControls.NodeTextBox();
                this.timer1 = new System.Windows.Forms.Timer(this.components);
                this.button1 = new System.Windows.Forms.Button();
                this.SuspendLayout();
                // 
                // nodeTextBox1
                // 
                this.nodeTextBox1.IncrementalSearchEnabled = true;
                this.nodeTextBox1.LeftMargin = 3;
                this.nodeTextBox1.ParentColumn = null;
                // 
                // nodeTextBox2
                // 
                this.nodeTextBox2.IncrementalSearchEnabled = true;
                this.nodeTextBox2.LeftMargin = 3;
                this.nodeTextBox2.ParentColumn = null;
                // 
                // _tree
                // 
                this._tree.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right)));
                this._tree.AutoRowHeight = true;
                this._tree.BackColor = System.Drawing.SystemColors.Window;
                this._tree.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
                this._tree.Columns.Add(this.treeColumn1);
                this._tree.Columns.Add(this.treeColumn2);
                this._tree.Cursor = System.Windows.Forms.Cursors.Default;
                this._tree.DefaultToolTipProvider = null;
                this._tree.DisplayDraggingNodes = true;
                this._tree.DragDropMarkColor = System.Drawing.Color.Black;
                this._tree.GridLineStyle = ((Aga.Controls.Tree.GridLineStyle)((Aga.Controls.Tree.GridLineStyle.Horizontal | Aga.Controls.Tree.GridLineStyle.Vertical)));
                this._tree.LineColor = System.Drawing.SystemColors.ControlDark;
                this._tree.LoadOnDemand = true;
                this._tree.Location = new System.Drawing.Point(12, 12);
                this._tree.Model = null;
                this._tree.Name = "_tree";
                this._tree.NodeControls.Add(this._name);
                this._tree.NodeControls.Add(this._value);
                this._tree.SelectedNode = null;
                this._tree.SelectionMode = Aga.Controls.Tree.TreeSelectionMode.MultiSameParent;
                this._tree.ShowNodeToolTips = true;
                this._tree.Size = new System.Drawing.Size(375, 223);
                this._tree.TabIndex = 1;
                this._tree.UseColumns = true;
                // 
                // treeColumn1
                // 
                this.treeColumn1.Header = "Name";
                this.treeColumn1.SortOrder = System.Windows.Forms.SortOrder.None;
                this.treeColumn1.TooltipText = "_name";
                this.treeColumn1.Width = 150;
                // 
                // treeColumn2
                // 
                this.treeColumn2.Header = "Value";
                this.treeColumn2.SortOrder = System.Windows.Forms.SortOrder.None;
                this.treeColumn2.TooltipText = "_value";
                this.treeColumn2.Width = 150;
                // 
                // _name
                // 
                this._name.DataPropertyName = "Name";
                this._name.IncrementalSearchEnabled = true;
                this._name.LeftMargin = 3;
                this._name.ParentColumn = this.treeColumn1;
                // 
                // _value
                // 
                this._value.DataPropertyName = "ItemValue";
                this._value.IncrementalSearchEnabled = true;
                this._value.LeftMargin = 3;
                this._value.ParentColumn = this.treeColumn2;
                // 
                // timer1
                // 
                this.timer1.Interval = 10;
                this.timer1.Tick += new System.EventHandler(this.Timer1Tick);
                // 
                // button1
                // 
                this.button1.Location = new System.Drawing.Point(46, 279);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 2;
                this.button1.Text = "button1";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.Button1Click);
                // 
                // MainForm
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
                this.ClientSize = new System.Drawing.Size(418, 442);
                this.Controls.Add(this.button1);
                this.Controls.Add(this._tree);
                this.Name = "MainForm";
                this.Text = "TestApplication";
                this.ResumeLayout(false);
    
            }
        }
    }
    
     
  • Laurent Nicot

    Laurent Nicot - 2015-10-08

    The third column is a real column or empty space (not a column) ?
    You can try to set AutoSpanColumns property (added in rev 94) to automatically adjust columns size

     
  • Andrew Ellis

    Andrew Ellis - 2015-10-09

    The thrid column should just be empty space. I have only added the first 2 columns in the column collection, _treecolumn1 & _treecolumn2. The columns have the heading Name and Value respectively.

    Setting the AutospanColumn property does mask the issue. Ideally I would like the area to be blank.

     

Log in to post a comment.