Collection with the correct object type on the Collection dialog

Discussion in 'ASP .Net Web Controls' started by Daniel Jorge, Jul 10, 2005.

  1. Daniel Jorge

    Daniel Jorge Guest

    Hi there,

    I'm new to webControls and I'm having a doubt regarding collection into
    the Control.
    Well, I've built a webCustomControl (let's call it MyPrimaryControl
    here) and it has a collection of custom objects (let's call it
    "MyCustomItem").
    I built a class called MyCustomItemCollection which implements IList,
    ICollection and IStateManager interfaces. No inheritances!
    I implemented all the mothods except the ones for ViewState management.
    IndexOf, Add, Insert, Remover and so on are all there!

    Now I get:
    MyPrimaryControl.CutomItems = MyCustomItemCollection

    When I use my primary control the property CustomItems (which is a
    collection) open up the Help dialog and let me add several System.Object
    objects into the collection. But yet, I can't edit any of them. I can't save
    the items as well.

    Does anybody know how to edit a collection with the correct object type,
    make it editable at Design-Time and force it to save the items into the
    object.

    Thanks in advance.

    Bye
    Daniel Jorge, Jul 10, 2005
    #1
    1. Advertising

  2. Daniel Jorge

    Guest

    Hi Daniel,

    You don't say if you're doing this in VB or C#. This is one area where
    doing it in C# will be easier.

    The thing is, your CollectionEditor can only show the properties of the
    items in the collection if the indexer of the collection is of the
    item's type.

    You might as well have inherited from ControlCollection or
    CollectionBase. The thing is, when you implement IList, you need to
    implement IList.Item. That's what the CollectionEditor picks up.

    I did this in VB, and had to do it like this:

    Private Property IList_Item(ByVal index As Integer) As Object _
    Implements IList.Item
    Get
    Return Me.owner.Controls.Item(index)
    End Get
    Set(ByVal Value As Object)
    Me.RemoveAt(index)
    Me.AddAt(index, CType(Value, Tab))
    End Set
    End Property 'Item

    Default Public ReadOnly Property Item(ByVal index As Integer) As Tab
    Get
    Return CType(Me.IList_Item(index), Tab)
    End Get
    End Property 'Item

    See, IList requires that the implementation of Item be of type Object.
    But that's no good for the CollectionEditor. So make the
    implementation property be private, and then have the default public
    property just a window into the implementation property. It's
    incredibly dumb, but there you are.

    In C#, it'd be like this:

    object IList.Item(int index)
    {
    get
    {
    return this.owner.Controls[index];
    }

    set
    {
    this.RemoveAt(index);
    this.AddAt(index, (Tab) value);
    }
    }

    public Tab this[int index]
    {
    get
    {
    return (Tab) this.owner.Controls[index];
    }
    }

    Hope that helps,
    Lisa



    Daniel Jorge wrote:
    > Hi there,
    >
    > I'm new to webControls and I'm having a doubt regarding collection into
    > the Control.
    > Well, I've built a webCustomControl (let's call it MyPrimaryControl
    > here) and it has a collection of custom objects (let's call it
    > "MyCustomItem").
    > I built a class called MyCustomItemCollection which implements IList,
    > ICollection and IStateManager interfaces. No inheritances!
    > I implemented all the mothods except the ones for ViewState management.
    > IndexOf, Add, Insert, Remover and so on are all there!
    >
    > Now I get:
    > MyPrimaryControl.CutomItems = MyCustomItemCollection
    >
    > When I use my primary control the property CustomItems (which is a
    > collection) open up the Help dialog and let me add several System.Object
    > objects into the collection. But yet, I can't edit any of them. I can't save
    > the items as well.
    >
    > Does anybody know how to edit a collection with the correct object type,
    > make it editable at Design-Time and force it to save the items into the
    > object.
    >
    > Thanks in advance.
    >
    > Bye
    , Jul 11, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    12,738
    Sean Foy
    Aug 6, 2006
  2. joon
    Replies:
    1
    Views:
    511
    Roedy Green
    Jul 8, 2003
  3. Dan

    correct or not correct?

    Dan, Oct 2, 2003, in forum: HTML
    Replies:
    7
    Views:
    433
  4. yw
    Replies:
    3
    Views:
    804
    Phlip
    Jul 2, 2005
  5. Øyvind Isaksen
    Replies:
    1
    Views:
    948
    Øyvind Isaksen
    May 18, 2007
Loading...

Share This Page