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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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());
}
}
}
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
Hi,
Add an example and an image depicting the issue, so it'll be easier to help you.
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
MetaItems.cs
MetaDisplayModel.cs
Last edit: Andrew Ellis 2015-10-07
Missing MainForm.Designer.cs file to see how _tree is defined
Hi I have pasted MainForm.Designer.cs below.
Andrew
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
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.