Click here to Skip to main content
16,015,097 members
Home / Discussions / C#
   

C#

 
Questionframes in asp.net Pin
raju_net181811-Jan-07 1:30
raju_net181811-Jan-07 1:30 
AnswerRe: frames in asp.net Pin
ednrgc11-Jan-07 2:17
ednrgc11-Jan-07 2:17 
GeneralRe: frames in asp.net Pin
raju_net181811-Jan-07 20:45
raju_net181811-Jan-07 20:45 
AnswerRe: frames in asp.net Pin
sanaziuse11-Jan-07 2:47
sanaziuse11-Jan-07 2:47 
GeneralRe: frames in asp.net Pin
raju_net181811-Jan-07 20:46
raju_net181811-Jan-07 20:46 
AnswerRe: frames in asp.net [modified] Pin
Not Active11-Jan-07 2:59
mentorNot Active11-Jan-07 2:59 
GeneralRe: frames in asp.net Pin
raju_net181811-Jan-07 20:43
raju_net181811-Jan-07 20:43 
QuestionPERSIST, DAMN YOU! Pin
Barguast211-Jan-07 1:13
Barguast211-Jan-07 1:13 
I'm trying to create a very simple Control that will host a collection of various objects. This is all the code amounts to:

using System;<br />
using System.Collections;<br />
using System.Collections.Generic;<br />
using System.Collections.ObjectModel;<br />
using System.Text;<br />
using System.ComponentModel.Design;<br />
using System.ComponentModel;<br />
using System.Drawing.Design;<br />
using System.ComponentModel.Design.Serialization;<br />
<br />
namespace Test<br />
{<br />
    [TypeConverter(typeof(ItemTypeConverter<BaseItem>))]<br />
    public class BaseItem<br />
    {<br />
        private string _itemName = "";<br />
<br />
        public string ItemName<br />
        {<br />
            get { return this._itemName; }<br />
            set { this._itemName = value; }<br />
        }<br />
    }<br />
<br />
    [TypeConverter(typeof(ItemTypeConverter<IntItem>))]<br />
    public class IntItem : BaseItem<br />
    {<br />
        private int _value = 0;<br />
<br />
        public int Value<br />
        {<br />
            get { return this._value; }<br />
            set { this._value = value; }<br />
        }<br />
    }<br />
<br />
    [TypeConverter(typeof(ItemTypeConverter<StringItem>))]<br />
    public class StringItem : BaseItem<br />
    {<br />
        private string _value = "";<br />
<br />
        public string Value<br />
        {<br />
            get { return this._value; }<br />
            set { this._value = value; }<br />
        }<br />
    }<br />
<br />
    public class ItemTypeConverter<T> : ExpandableObjectConverter<br />
    {<br />
        public ItemTypeConverter()<br />
            : base()<br />
        {<br />
<br />
        }<br />
<br />
        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)<br />
        {<br />
            if (destinationType == typeof(InstanceDescriptor))<br />
                return true;<br />
            else<br />
                return base.CanConvertTo(context, destinationType);<br />
        }<br />
<br />
        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)<br />
        {<br />
            if (destinationType == typeof(InstanceDescriptor))<br />
                return new InstanceDescriptor(typeof(T).GetConstructor(new Type[0]), null, false);<br />
            else<br />
                return base.ConvertTo(context, culture, value, destinationType);<br />
        }<br />
    }<br />
<br />
    [TypeConverter(typeof(ItemTypeConverter<ItemCollection2>))]<br />
    public class ItemCollection2 : CollectionBase<br />
    {<br />
        internal ItemCollection2()<br />
        {<br />
        }<br />
<br />
        public BaseItem Add(BaseItem item)<br />
        {<br />
            this.InnerList.Add(item);<br />
            return item;<br />
        }<br />
<br />
        public void Remove(BaseItem item)<br />
        {<br />
            this.InnerList.Remove(item);<br />
        }<br />
<br />
        public bool Contains(BaseItem item)<br />
        {<br />
            return this.InnerList.Contains(item);<br />
        }<br />
<br />
        public BaseItem this[int i]<br />
        {<br />
            get { return (BaseItem)this.InnerList[i]; }<br />
        }<br />
    }<br />
<br />
    public class ItemCollectionEditor : CollectionEditor<br />
    {<br />
        private static Type[] types;<br />
<br />
        public ItemCollectionEditor(Type type)<br />
            : base(type)<br />
        {<br />
            types = new Type[] { typeof(IntItem), typeof(StringItem) };<br />
        }<br />
<br />
        protected override Type[] CreateNewItemTypes()<br />
        {<br />
            return types;<br />
        }<br />
    }<br />
<br />
    public class ItemCollectionHostControl : System.Windows.Forms.Control<br />
    {<br />
        private ItemCollection2 _items;<br />
<br />
        public ItemCollectionHostControl()<br />
        {<br />
            this._items = new ItemCollection2();<br />
        }<br />
<br />
        [Editor(typeof(ItemCollectionEditor), typeof(UITypeEditor)),<br />
         DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]<br />
        public ItemCollection2 Items<br />
        {<br />
            get { return this._items; }<br />
        }<br />
    }<br />
}



However, whenever I add items to the control, the Designer does not generate any code for them. As a result, whenever I build the project, the collection items are lost.

Can anyone see what I'm doing wrong? This is merely an example of something more complicated that I'm trying to achieve by the way - this problem is proving to be a major stumbling block. Frown | :(

Thanks in advance.
QuestionGarbage Collector Pin
Ashwani_kumar11-Jan-07 1:08
Ashwani_kumar11-Jan-07 1:08 
AnswerRe: Garbage Collector Pin
MCSD-Gandalf11-Jan-07 2:22
MCSD-Gandalf11-Jan-07 2:22 
GeneralRe: Garbage Collector Pin
Ashwani_kumar11-Jan-07 2:41
Ashwani_kumar11-Jan-07 2:41 
GeneralRe: Garbage Collector Pin
Mircea Puiu11-Jan-07 2:57
Mircea Puiu11-Jan-07 2:57 
GeneralRe: Garbage Collector Pin
Colin Angus Mackay11-Jan-07 4:46
Colin Angus Mackay11-Jan-07 4:46 
GeneralRe: Garbage Collector Pin
Dave Kreskowiak11-Jan-07 5:41
mveDave Kreskowiak11-Jan-07 5:41 
GeneralRe: Garbage Collector Pin
Dan Neely11-Jan-07 6:56
Dan Neely11-Jan-07 6:56 
GeneralRe: Garbage Collector Pin
Dave Kreskowiak11-Jan-07 12:06
mveDave Kreskowiak11-Jan-07 12:06 
AnswerRe: Garbage Collector Pin
Colin Angus Mackay11-Jan-07 4:42
Colin Angus Mackay11-Jan-07 4:42 
AnswerRe: Garbage Collector Pin
Dave Kreskowiak11-Jan-07 4:44
mveDave Kreskowiak11-Jan-07 4:44 
QuestionWhen is [Serializable] enough ? Pin
MarkPhB11-Jan-07 0:28
MarkPhB11-Jan-07 0:28 
AnswerRe: When is [Serializable] enough ? Pin
J4amieC11-Jan-07 0:44
J4amieC11-Jan-07 0:44 
GeneralRe: When is [Serializable] enough ? Pin
MarkPhB11-Jan-07 1:14
MarkPhB11-Jan-07 1:14 
GeneralRe: When is [Serializable] enough ? Pin
Bekjong11-Jan-07 1:26
Bekjong11-Jan-07 1:26 
GeneralRe: When is [Serializable] enough ? Pin
MarkPhB11-Jan-07 2:26
MarkPhB11-Jan-07 2:26 
GeneralRe: When is [Serializable] enough ? Pin
Bekjong11-Jan-07 2:59
Bekjong11-Jan-07 2:59 
QuestionToolStripProgressBar/Progressbar Pin
GunaChinna11-Jan-07 0:17
GunaChinna11-Jan-07 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.