array of objects in a User Control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Vincent Finn

    #1

    array of objects in a User Control

    Hi,

    I am writing a Control (in C#) and I want to give the user access to
    an array of items in it.
    If I make a property that returns the array it doesn't work properly
    in the designer.

    The control properties in design mode show my propery
    I can select it
    that brings up a window that allows me to add new items and set their
    properties
    This seems to work and the new items are displayed
    As soon as I compile they vanish.

    The array created in the property editor seems to be loaded into
    memory but not saved in the .cs file

    I can use the property fine in my code it is just in the property
    window I can't.

    Here is the definitions I am using, nothing special about them

    Anyone any idea what I am doing wrong?

    Vin

    /////////////////////////////////////////////////////////

    // in the Control
    private Test[] m_aTests;
    public Test[] Tests
    {
    get
    {
    return m_aTests;
    }
    set
    {
    m_aTests = value;
    }
    }

    // the class Test
    public class Test
    {
    private int m_i;
    public Test()
    {
    }
    public int i
    {
    get
    {
    return m_i;
    }
    set
    {
    m_i = value;
    }
    }
    }

  • Marina

    #2
    Re: array of objects in a User Control

    I dont' think the designer can serialize it to the array very well, because
    it would have to constantly be changing its size. I have done this with
    stringcollectio ns, and that works well.

    "Vincent Finn" <1@2.com> wrote in message
    news:36n4o0tsa1 fts3452npg1489c blrekesth@4ax.c om...[color=blue]
    > Hi,
    >
    > I am writing a Control (in C#) and I want to give the user access to
    > an array of items in it.
    > If I make a property that returns the array it doesn't work properly
    > in the designer.
    >
    > The control properties in design mode show my propery
    > I can select it
    > that brings up a window that allows me to add new items and set their
    > properties
    > This seems to work and the new items are displayed
    > As soon as I compile they vanish.
    >
    > The array created in the property editor seems to be loaded into
    > memory but not saved in the .cs file
    >
    > I can use the property fine in my code it is just in the property
    > window I can't.
    >
    > Here is the definitions I am using, nothing special about them
    >
    > Anyone any idea what I am doing wrong?
    >
    > Vin
    >
    > /////////////////////////////////////////////////////////
    >
    > // in the Control
    > private Test[] m_aTests;
    > public Test[] Tests
    > {
    > get
    > {
    > return m_aTests;
    > }
    > set
    > {
    > m_aTests = value;
    > }
    > }
    >
    > // the class Test
    > public class Test
    > {
    > private int m_i;
    > public Test()
    > {
    > }
    > public int i
    > {
    > get
    > {
    > return m_i;
    > }
    > set
    > {
    > m_i = value;
    > }
    > }
    > }
    >[/color]


    Comment

    • Vincent Finn

      #3
      Re: array of objects in a User Control

      On Fri, 29 Oct 2004 14:59:57 -0400, "Marina" <someone@nospam .com>
      wrote:
      [color=blue]
      >I dont' think the designer can serialize it to the array very well, because
      >it would have to constantly be changing its size. I have done this with
      >stringcollecti ons, and that works well.[/color]

      I have seen 3rd party controls handle it
      but looking at them agani I think they may be using custom editors
      rather than a simple built in one the way I thought they were

      So maybe I was just assuming it was easier than it is

      Will have to look into the custom editors

      Thanks

      Vin

      Comment

      Working...