ITEM CLASS:
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace AssistApplications.Windows.Forms
{
[DesignTimeVisible(false)]
public class CategoryItem : System.ComponentModel.Component
{
private string fTitle;
private CategoryItemCollection fSubItems;
private string fValue;
public CategoryItem()
{
fSubItems = new CategoryItemCollection();
}
public string Title
{
get { return fTitle; }
set { fTitle = value; }
}
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public CategoryItemCollection SubItems
{
get { return fSubItems; }
}
public string Value
{
get { return fValue; }
set { fValue = value; }
}
}
}
ITEM COLLECTION:
using System;
using System.Collections;
using System.Windows.Forms;
namespace AssistApplications.Windows.Forms
{
public class CategoryItemCollection : System.Collections.CollectionBase
{
public delegate void CollectionChange(int index, object value);
private event CollectionChange fInserting;
private event CollectionChange fInsertComplete;
protected override void OnInsert(int index, object value)
{
CategoryItem item = value as CategoryItem;
if(item.Title == null)
item.Title = String.Concat("Item", Count.ToString());
base.OnInsert(index, item);
if(fInserting != null)
{
fInserting(index, value);
}
}
protected override void OnInsertComplete(int index, object value)
{
base.OnInsertComplete (index, value);
if(fInsertComplete != null)
{
fInsertComplete(index, value);
}
}
public CategoryItemCollection(){}
public int Add(CategoryItem item)
{
if(Contains(item)) return -1;
int index = List.Add(item);
//OnAddPanel(new PanelEventArgs(panel));
return index;
}
public void AddRange(CategoryItem[] items)
{
foreach(CategoryItem item in items)
Add(item);
}
public void Remove(int index)
{
if((index >= Count) || (index < 0))
return;
List.RemoveAt(index);
}
public CategoryItem this[int index]
{
get
{
if(index < 0 || index >= Count)
return null;
return (CategoryItem)List[index];
}
}
public void Insert(int index, CategoryItem item)
{
List.Insert(index, item);
}
public int IndexOf(CategoryItem item)
{
return List.IndexOf(item);
}
public bool Contains(CategoryItem item)
{
return InnerList.Contains(item);
}
public event CollectionChange Inserting
{
add { fInserting += value; }
remove { fInserting -= value; }
}
public event CollectionChange InsertComplete
{
add { fInsertComplete += value; }
remove { fInsertComplete -= value; }
}
}
}
Control class:
refences the items as in item but with the name as Items e.g.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public CategoryItemCollection Items
{
get { return fItems; }
}
What I'm trying to do is like treenode and menitems they can subitems of the
same type but trying to do this at design time.
if i load it at runtime it works fine. I have no idea on how to do this and
there is no help out there.
Thanks,
ash.
codewriter said: