Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Collection Editor Question

Collection Editor Question

Scheduled Pinned Locked Moved ASP.NET
tutorialquestiondesigndata-structures
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    work_to_live
    wrote on last edited by
    #1

    I'm trying to do something relatively simple (or so I thought). I built a custom control, and I want to be able to add an array of strings to it at design time. From the little research I've done, it looks like I need to create a CollectionEditor based class, and override some of the methods to provide the specifics of my collection. In addition I reference the new class in an attribute for the property. For the life of me, I can't seem to find the right recipe. A couple of questions... Is there a simple way to add an array of strings to a custom control at design time? If not, can you provide an example of how to use the CollectionEditor class to add an array of strings to a custom control? Thanks... Frustrated...

    B 1 Reply Last reply
    0
    • W work_to_live

      I'm trying to do something relatively simple (or so I thought). I built a custom control, and I want to be able to add an array of strings to it at design time. From the little research I've done, it looks like I need to create a CollectionEditor based class, and override some of the methods to provide the specifics of my collection. In addition I reference the new class in an attribute for the property. For the life of me, I can't seem to find the right recipe. A couple of questions... Is there a simple way to add an array of strings to a custom control at design time? If not, can you provide an example of how to use the CollectionEditor class to add an array of strings to a custom control? Thanks... Frustrated...

      B Offline
      B Offline
      benqazou
      wrote on last edited by
      #2

      Wouldn't a sipmle ArrayList do the job??

      W 1 Reply Last reply
      0
      • B benqazou

        Wouldn't a sipmle ArrayList do the job??

        W Offline
        W Offline
        work_to_live
        wrote on last edited by
        #3

        Same question... How do you implement an ArrayList property, with designer support? I also played with that, but no success. I found another way to implement the functionality I was looking for, but I'd still like to know how to create collection properties with designer support. Most of the CollectionEditor descriptions/examples make assumptions about the experience level of the reader, and it looks like I've got a ways to go yet:) FYI I have a navigation header with a different set of images I swap in whenever the it's rendered. I didn't want the overhead of AdRotator, so I rolled my own. The string list (ArrayList) provided the list of images. The alternative solution I came up with was simpler... I created a new folder under images, and put all the images I want in my header in that folder. Now when I want to add a new image to the header, I just add it to that folder, and it appears! Simple... But it would be nice to have the property collection understanding.

        M 1 Reply Last reply
        0
        • W work_to_live

          Same question... How do you implement an ArrayList property, with designer support? I also played with that, but no success. I found another way to implement the functionality I was looking for, but I'd still like to know how to create collection properties with designer support. Most of the CollectionEditor descriptions/examples make assumptions about the experience level of the reader, and it looks like I've got a ways to go yet:) FYI I have a navigation header with a different set of images I swap in whenever the it's rendered. I didn't want the overhead of AdRotator, so I rolled my own. The string list (ArrayList) provided the list of images. The alternative solution I came up with was simpler... I created a new folder under images, and put all the images I want in my header in that folder. Now when I want to add a new image to the header, I just add it to that folder, and it appears! Simple... But it would be nice to have the property collection understanding.

          M Offline
          M Offline
          minhpc_bk
          wrote on last edited by
          #4

          Hi there, If you want to use a custom collection editor to edit the collection property of a web custom control, the type of the collection item must have the default constructor. So you should define a custom class which represents for each item in the ArrayList, say NavigatorItem. The markup of the Navigator custom control looks something like at design time:

          <cc1:Navigator id="Navigator1" runat="server">
          <cc1:NavigatorItem ImageUrl="Images/Image1.gif"></cc1:NavigatorItem>
          <cc1:NavigatorItem ImageUrl="Images/Image2.gif"></cc1:NavigatorItem>
          </cc1:Navigator>

          So, you basically have to define a collection property in the custom control:

          private ArrayList images;

          [Category("Data"),
          Description("Navigation Header Images"),
          DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
          System.ComponentModel.Editor(typeof(ImageCollectionEditor), typeof(UITypeEditor)),
          PersistenceMode(PersistenceMode.InnerDefaultProperty)]
          public ArrayList Images
          {
          get
          {
          if(images==null)
          images = new ArrayList();

          	return images;
          }
          

          }

          You should remember to attach the attribute [ParseChildren(true, "Images")] to the custom control definition. Here, I define a custom simple collection editor called ImageCollectionEditor:

          public class ImageCollectionEditor : CollectionEditor
          {
          public ImageCollectionEditor(Type type) : base(type)
          {
          }

          protected override bool CanSelectMultipleInstances()
          {
          	return false;
          }
                       
          protected override Type CreateCollectionItemType()
          {
                      //Specify the collection item's type.  
          	return typeof(NavigatorItem);
          }
          

          }

          [TypeConverter(typeof(ExpandableObjectConverter))]
          public class NavigatorItem
          {
          private string image;

          \[DefaultValue("")\]
          \[NotifyParentProperty(true)\]
          public string ImageUrl
          {
          	get{return image;}
          	set{image = value;}
          }
          

          }

          The NavigatorItem class represents for each item in the collection.

          W 1 Reply Last reply
          0
          • M minhpc_bk

            Hi there, If you want to use a custom collection editor to edit the collection property of a web custom control, the type of the collection item must have the default constructor. So you should define a custom class which represents for each item in the ArrayList, say NavigatorItem. The markup of the Navigator custom control looks something like at design time:

            <cc1:Navigator id="Navigator1" runat="server">
            <cc1:NavigatorItem ImageUrl="Images/Image1.gif"></cc1:NavigatorItem>
            <cc1:NavigatorItem ImageUrl="Images/Image2.gif"></cc1:NavigatorItem>
            </cc1:Navigator>

            So, you basically have to define a collection property in the custom control:

            private ArrayList images;

            [Category("Data"),
            Description("Navigation Header Images"),
            DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
            System.ComponentModel.Editor(typeof(ImageCollectionEditor), typeof(UITypeEditor)),
            PersistenceMode(PersistenceMode.InnerDefaultProperty)]
            public ArrayList Images
            {
            get
            {
            if(images==null)
            images = new ArrayList();

            	return images;
            }
            

            }

            You should remember to attach the attribute [ParseChildren(true, "Images")] to the custom control definition. Here, I define a custom simple collection editor called ImageCollectionEditor:

            public class ImageCollectionEditor : CollectionEditor
            {
            public ImageCollectionEditor(Type type) : base(type)
            {
            }

            protected override bool CanSelectMultipleInstances()
            {
            	return false;
            }
                         
            protected override Type CreateCollectionItemType()
            {
                        //Specify the collection item's type.  
            	return typeof(NavigatorItem);
            }
            

            }

            [TypeConverter(typeof(ExpandableObjectConverter))]
            public class NavigatorItem
            {
            private string image;

            \[DefaultValue("")\]
            \[NotifyParentProperty(true)\]
            public string ImageUrl
            {
            	get{return image;}
            	set{image = value;}
            }
            

            }

            The NavigatorItem class represents for each item in the collection.

            W Offline
            W Offline
            work_to_live
            wrote on last edited by
            #5

            Thanks, I'll give this a shot!

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups