////////////////////////
//Tree
///////////////////////
using System;
using System.Collections;
namespace SampleTree
{
public class TreeNode
{
#region The TreeNodeCollection class.
public class TreeNodeCollection:ICollection
{
private TreeNode _owner=null;
private ArrayList _innerList=new ArrayList();
public TreeNodeCollection(TreeNode owner)
{
this._owner=owner;
}
public TreeNode this[int index]
{
get{return (TreeNode)this._innerList[index];}
set
{
if(value ==null)
throw new ArgumentNullException();
(this._innerList[index] as TreeNode)._parent=null;;
value._parent=this._owner;
this._innerList[index]=value;
}
}
public bool IsSynchronized
{
get{ return this._innerList.IsSynchronized;}
}
public int Count
{
get{ return this._innerList.Count;}
}
public void CopyTo(Array array, int index)
{
this._innerList.CopyTo(array,index);
}
public object SyncRoot
{
get
{
return this._innerList.SyncRoot;
}
}
public IEnumerator GetEnumerator()
{
return this._innerList.GetEnumerator();
}
public int Add(TreeNode value)
{
if(value ==null)
throw new ArgumentNullException();
value._parent=this._owner;
return this._innerList.Add(value);
}
public void Insert(int index, TreeNode value)
{
if(value ==null)
throw new ArgumentNullException();
value._parent=this._owner;
this._innerList.IndexOf(value,index);
}
public void RemoveAt(int index)
{
try
{
this[index]._parent=null;
this._innerList.RemoveAt(index);
}
catch
{
}
}
public int IndexOf(TreeNode value)
{
return this._innerList.IndexOf(value);
}
public void Clear()
{
for(int i=0;i<this.Count;i++)
{
this[i]._parent=null;
}
this._innerList.Clear();
}
public bool Contains(TreeNode value)
{
return this._innerList.Contains(value);
}
}
#endregion