|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Collection with the correct object type on the Collection dialogI'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 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: Show quoteHide quote > 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
Custom control: How to render an embedded image at design-time?
Render and Image on a Button Can aspnet simulate windows pane separator? Web User Controls: Exposing Items property of contained controls Load User Control from different directory DropDownList <optgroup> WinForm as ASP.NET custom control Tool to monitor/trace all method calls? Webcontrol Designer Awareness... Re: accessibility and asp:button |
|||||||||||||||||||||||