ITEM CLASS:
using System;
using System.Componen tModel;
using System.Windows. Forms;
namespace AssistApplicati ons.Windows.For ms
{
[DesignTimeVisib le(false)]
public class CategoryItem : System.Componen tModel.Componen t
{
private string fTitle;
private CategoryItemCol lection fSubItems;
private string fValue;
public CategoryItem()
{
fSubItems = new CategoryItemCol lection();
}
public string Title
{
get { return fTitle; }
set { fTitle = value; }
}
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
public CategoryItemCol lection SubItems
{
get { return fSubItems; }
}
public string Value
{
get { return fValue; }
set { fValue = value; }
}
}
}
ITEM COLLECTION:
using System;
using System.Collecti ons;
using System.Windows. Forms;
namespace AssistApplicati ons.Windows.For ms
{
public class CategoryItemCol lection : System.Collecti ons.CollectionB ase
{
public delegate void CollectionChang e(int index, object value);
private event CollectionChang e fInserting;
private event CollectionChang e 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(i ndex, item);
if(fInserting != null)
{
fInserting(inde x, value);
}
}
protected override void OnInsertComplet e(int index, object value)
{
base.OnInsertCo mplete (index, value);
if(fInsertCompl ete != null)
{
fInsertComplete (index, value);
}
}
public CategoryItemCol lection(){}
public int Add(CategoryIte m item)
{
if(Contains(ite m)) return -1;
int index = List.Add(item);
//OnAddPanel(new PanelEventArgs( panel));
return index;
}
public void AddRange(Catego ryItem[] items)
{
foreach(Categor yItem item in items)
Add(item);
}
public void Remove(int index)
{
if((index >= Count) || (index < 0))
return;
List.RemoveAt(i ndex);
}
public CategoryItem this[int index]
{
get
{
if(index < 0 || index >= Count)
return null;
return (CategoryItem)L ist[index];
}
}
public void Insert(int index, CategoryItem item)
{
List.Insert(ind ex, item);
}
public int IndexOf(Categor yItem item)
{
return List.IndexOf(it em);
}
public bool Contains(Catego ryItem item)
{
return InnerList.Conta ins(item);
}
public event CollectionChang e Inserting
{
add { fInserting += value; }
remove { fInserting -= value; }
}
public event CollectionChang e InsertComplete
{
add { fInsertComplete += value; }
remove { fInsertComplete -= value; }
}
}
}
Control class:
refences the items as in item but with the name as Items e.g.
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
public CategoryItemCol lection 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 " <co************ **@yahoo.com> wrote in message
news:pG******** ***********@new s20.bellglobal. com...
Post your code.
"Ash Jones" <as*@ashtek.me. uk> wrote in message
news:OR******** *****@tk2msftng p13.phx.gbl... I trying to do nested items in a collection.
I've got an item which one of the properties is subitems, which is a
collection of item. can do the root level but if i do a subitem at
design time i get an object not set error. it's like a menuitem or treenode
which can have subitems of the same type. cant find any help on nested items.
is there anyone out there that help?
Many thanks,
ash.