save Object's Property at design time

I have a collection object and use Object Collection Editor to add new object and edit property value. but How to save these new values
 Thanks


Answer this question

save Object's Property at design time

  • scJohn

    Not sure if this is the right way to solve this problem, but I think it might work.  It's hard to tell sometimes because you're not sure if there's a bug in the designer that's causing your problem.  So closing the IDE and reopening it is always a good option.  So here's what I did to fix the problem -- in your user control's InitializeComponent(), make sure that when it creates a new object of the inner controls of your user control that it's calling the constructor with no parameters instead of the one that takes a System.ComponentModel.IContainer.  This seemed to make it work for me, but I haven't played with it much yet.  So we'll see if it holds up.

    Jon

  • David Wrighton

    Hi,

    Very greats thank for your help.

    I will test this link.

    Thanks

  • kiran1234

    Have a look at this article:

    http://msdn.microsoft.com/library/default.asp url=/library/en-us/dndotnet/html/custcodegen.asp



    Also some ware next week I will publish the SmartLibrary with the source code, and it is using custom collections, I am adding the final touches to the code.

  • Dieter De Preester

    I would try changing the value of the attribute from "Visible" to "Content."
  • implemental.com

    I faced the same kind of problem long time ago; I remember fixing it by inheriting the CollectionBase class for my collection class, and by marking my items that are used in the collection as [Serializeble] and of course the [DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)] attribute.
  • Andy Milligan

    I tried Content as well as Visible, still with no luck.  I'm pretty sure I'm missing some decoration on the type that I'm storing in the collection (ListItem).  I somehow need to tell the designer how to serialize it's state to code.  I tried putting [Serializable()] on the ListItem class and the designer tried to store the state in a resource file, so I think I'm getting close.

    Thanks,
    Todd

  • aKzenT

    Your class needs to Implement ISupportIntialize. Look at the EndInit() Method.

    Sam


  • Oli is cool

    I've tried using the DesignerSerializationVisibility attribute, but code for my collection property is still not being generated in the class containing the control.  I've defined a strongly-typed collection (see code below), and I've decorated my property of this collection type with the attribute.  I build the project, create a test form, and drag the control onto the design surface.  I can edit the collection just fine, but after I'm done, the collection items are not persisted in the code.  What am I missing

    Thanks,
    Todd Gray

    Property declaration:

    private ButtonItemList _items = new ButtonItemList();
    [DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Visible)] 
    public ButtonItemList Items
    {
    get { return _items; }
    set { _items = value; }
    }



    Collection code:

    public class ListItem
    {
    private string _itemtext = "";
    private ItemType _itemtype = ItemType.Button;
    private string _itemcommand = "";
    public string ItemText
    {
    get { return _itemtext; }
    set { _itemtext = value; }
    }
    public ItemType ItemType
    {
    get { return _itemtype; }
    set { _itemtype = value; }
    }
    public string ItemCommand
    {
    get { return _itemcommand; }
    set { _itemcommand = value; }
    }
    }
    public enum ItemType
    {
    Button,
    Separator
    }
    public class ButtonItemList : System.Collections.CollectionBase
    {
    public ButtonItemList()
    {
    }
    private ButtonList _parent;
    public ButtonItemList(ButtonList parent)
    {
    _parent = parent;
    }

    public delegate void ChangedEventHandler();

    public event ChangedEventHandler Changed;

    public ListItem this[int index]
    {
    get { return (ListItem)List[index]; }
    set { List[index] = value; Changed(); }
    }
    public void Add(ListItem Value)
    {
    List.Add(Value);
    Changed();
    }
    public void Insert(int index, ListItem Value)
    {
    List.Insert(index, Value);
    Changed();
    }
    public void Remove(ListItem Value)
    {
    List.Remove(Value);
    Changed();
    }
    public int IndexOf(ListItem Value)
    {
    return List.IndexOf(Value);
    }
    public bool Contains(ListItem Value)
    {
    return List.Contains(Value);
    }
    }
    }

  • Harry Solsem

    Hi,

    I have exactly the same problem and i would like to know if you have found the solution.

    So, if you have the solution ca you send me an example to DotNET74@tiscali.fr

    Greats thanks


  • FredZmith

    The property that represents your collection object needs to have a particular attribute on it:

    <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public ReadOnly MyProperty() As MyCollection
         Get
              'whatever....
         End Get
    End Property

  • Babant

    Hi,

    Very thanks for this informations but can you send me an example to DotNET74@tiscali.fr
    because i m very stopped by this problem since one month :(((((

    Thanks

  • save Object's Property at design time