System.ComponentModel.Design.ArrayEditor - How to

Ask a Question related to ASP.NET Building Controls, Design and Development.

  1. #1

    Default System.ComponentModel.Design.ArrayEditor - How to

    I have a custom control which is a set of tab images like in hotmail. In my control I have a hard coded array that sets the string
    value of the tabs.

    private String[] tabCaptions = { "Home", "Tab 1", "Tab 2", "Tab 3" };

    I would like these tab captions set by the user of my control via the properties window. i.e. the code below that I have so far.

    using System;
    using System.ComponentModel.Design;

    namespace NetParadigm.WebServerControls
    {
    public class TabEditor : ArrayEditor
    {
    public TabEditor() : base (typeof ( String ) )
    {
    }
    }
    }

    Then I specify this editor via the editor attribute for my TabCaptions property as below

    private String[] tabCaptions;

    [EditorAttribute("TabEditor",typeof(System.Drawing. Design.UITypeEditor))]
    public String[] TabCaptions
    {
    get
    {
    return tabCaptions;
    }
    set
    {
    tabCaptions = value;
    }
    }

    This is just stubbed code and as far as I could get. This gives me an editor (i.e. click on the ellipse) window exactly like a
    windows forms textbox when you set the Lines property values.

    When these string values are set via this edior when my control is on a aspx page I get the below in Html view for the control

    <cc1:NP_TabStrip id=NP_TabStrip1 runat="server" TabCaptions="String[] Array">

    Of course I need to persist these values via view state and TabCaptions="String[] Array" bombs big time!

    I've searched everywhere for an example of how to set a string array in my control and come up with a lot of fragments and unrelated
    stuff. The Kothari book has an example of a CollectionEditor that is way too complex to disseminate for my use. Any ideas or a good
    example of how to do this would be greatly appreciated. Thanks in advance.

    Peter Ehli



    Peter Ehli Guest

  2. Similar Questions and Discussions

    1. System.ComponentModel.Win32Exception: Access is denied
      Hi, From a web application using following code iam executing an EXE. IPTCProcessInfo.FileName = "C:\\IMGExtractor.exe"; ...
    2. Hello Error with Web Services. No se puede serializar el miembro System.ComponentModel.MarshalByValueComponent.Site de tipo System.ComponentModel.ISite porque es una interfaz.
      Hello I have a solution iwth a web project and web service project I made a project and I compiled it and it has no errors. But when I try to add...
    3. Preventing users from adding items in ArrayEditor
      I've been trying to implement a way to edit a property (containing an Array of private objects) on a webcontrol at design-time ... my first shot...
    4. Significance of System.ComponentModel, IComponent, etc.
      Hi. I'm looking for in-depth resources on the use of the System.ComponentModel namespace, namely the Component class and the IComponent interface....
    5. System.Web.UI.Design
      I have been reading about creating custom controls and many of them use the System.Web.UI.Design namespace. I don't have access to it. How do I...
  3. #2

    Default RE: System.ComponentModel.Design.ArrayEditor - How to

    You need to change the default serialization behaviour that the designer uses
    by
    adding attributes to the property.

    [DesignerSerializationVisibility( DesignerSerializationVisibility.Content ),
    PersistenceMode( PersistenceMode.Attribute )]

    This should force the dte to serialize the content of your property ie the
    string values, instead of the property itself, ie an array.

    Chris
    ChrisAdams Guest

  4. #3

    Default Re: System.ComponentModel.Design.ArrayEditor - How to

    Hi Chris,
    My property attributes are below and as you can see I added the DesignerSerializationVisibility and PersistenceMode attribute to my
    property as you suggested.

    [EditorAttribute( "TabEditor",typeof( System.Drawing.Design.UITypeEditor )),
    DesignerSerializationVisibility( DesignerSerializationVisibility.Content ),
    PersistenceMode( PersistenceMode.Attribute )]
    public String[] TabCaptions
    {
    get
    {
    return tabCaptions;
    }
    set
    {
    tabCaptions = value;
    }
    }

    private String[] tabCaptions;

    When I set the string values i.e. TabCaptons via the editor for my control on an aspx page I get the below in Html view from the
    aspx page.

    <cc1:NP_TabStrip id=NP_TabStrip1 runat="server" TabCaptions-Rank="1" TabCaptions-IsReadOnly="False"
    TabCaptions-SyncRoot="System.String[]" TabCaptions-IsSynchronized="False" TabCaptions-IsFixedSize="True" TabCaptions-Length="4"
    TabCaptions-LongLength="4" TabCaptions="String[] Array">

    This gives me a parser error below when trying to render the page in the browser

    Parser Error Message: Cannot create an object of type 'System.String[]' from its string representation 'String[] Array' for the
    'TabCaptions' property.

    Again below is my designer class.

    using System;
    using System.ComponentModel.Design;

    namespace NetParadigm.WebServerControls
    {
    public class TabEditor : ArrayEditor
    {
    public TabEditor() : base (typeof ( String ) )
    {
    }
    }
    }

    Any ideas on whats wrong? Thanks Chris!

    <nospam="pehli1@hotmail.com"/><nospam>



    "ChrisAdams" <ChrisAdams@discussions.microsoft.com> wrote in message news:2F540031-C865-482D-9959-3D1E02128BE7@microsoft.com...
    > You need to change the default serialization behaviour that the designer uses
    > by
    > adding attributes to the property.
    >
    > [DesignerSerializationVisibility( DesignerSerializationVisibility.Content ),
    > PersistenceMode( PersistenceMode.Attribute )]
    >
    > This should force the dte to serialize the content of your property ie the
    > string values, instead of the property itself, ie an array.
    >
    > Chris

    Peter Ehli Guest

  5. #4

    Default Re: System.ComponentModel.Design.ArrayEditor - How to

    Whoops,

    I forgot that it only works for properties that expose a collection object,
    and you need to
    persist it as an inner property.

    What you probably need to do is specify the TypeConverter that should be
    used to get
    it from an array to a string representation. Take a look at ArrayConverter
    and the
    attribute you need to apply is.

    [TypeConverter( typeof( System.ComponentModel.ArrayConverter) )]

    Chris.
    ChrisAdams Guest

  6. #5

    Default Re: System.ComponentModel.Design.ArrayEditor - How to

    Thanks Chris, I believe my next step is to work through chapter 10 and the examples of the Kothari book. This chapter explains
    typeconveters, inner
    property persistence, and designer serialization and so forth. Again many thanks for pointing me in the right direction.

    Peter Ehli



    "ChrisAdams" <ChrisAdams@discussions.microsoft.com> wrote in message news:0CEC9F10-EA6C-4F1C-B5C0-7ADC7D382E05@microsoft.com...
    > Whoops,
    >
    > I forgot that it only works for properties that expose a collection object,
    > and you need to
    > persist it as an inner property.
    >
    > What you probably need to do is specify the TypeConverter that should be
    > used to get
    > it from an array to a string representation. Take a look at ArrayConverter
    > and the
    > attribute you need to apply is.
    >
    > [TypeConverter( typeof( System.ComponentModel.ArrayConverter) )]
    >
    > Chris.


    Peter Ehli Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139