Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Custom Collection Question
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01395070
Message ID:
01395079
Views:
44
>I have coded a custom collection. It will be set up as a property on a user control.
>
>The property:
>
>private HeaderCollection _Headers = new HeaderCollection();
>public HeaderCollection Headers
>{
>    get { return _Headers; }
>    set { _Headers = value; }
>}
>
>
>Now the collection class:
>
>public class HeaderCollection : CollectionBase
>{
>    public ColumnHeader this[int index]
>    {
>        get { return (ColumnHeader)InnerList[index]; }
>        set { InnerList[index] = value; }
>    }
>    public HeaderCollection()
>    {
>    }
>
>    public int Add(ColumnHeader Header)
>    {
>        return InnerList.Add(Header);
>    }
>
>    public int IndexOf(ColumnHeader Header)
>    {
>        return InnerList.IndexOf(Header);
>    }
>
>    public void Insert(int index, ColumnHeader Header)
>    {
>        InnerList.Insert(index, Header);
>    }
>
>    public void Remove(ColumnHeader Header)
>    {
>        InnerList.Remove(Header);
>    }
>
>    public bool Contains(ColumnHeader Header)
>    {
>        return InnerList.Contains(Header);
>    }
>}
>
>
>Then in the form I have:
>
>MyControl.ColumnHeader oHeader1 = new MyControl.ColumnHeader();
>MyControl.Headers.Add(oHeader1);
>
>
>The question is - when a header is added to the collection, I see the code in the Add overload running, but how do I add the control to the user control? The Collection class has no reference to the parent or to the UserControl.

Hi,
Don't think there is an answer to your question. If the collection has no reference to the UserControl then you simply can't add the item to the usercontrol from within the collection. Perhaps you need to explain the architecture a bit more.

BTW why didn't you just base your HeaderCollection class on a generic collection:
public class HeaderCollection : Collection<ColumnHeader>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform