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. General Programming
  3. C#
  4. Customizing .NET Collection Editor

Customizing .NET Collection Editor

Scheduled Pinned Locked Moved C#
csharpdesignhelptutorial
4 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.
  • H Offline
    H Offline
    heavenamour
    wrote on last edited by
    #1

    :confused:Hi every body I Wrote a calendar class that have a collection of holidays as an ArrayList. This collection is a property of my custom control that I want Add some objects of Holiday class to it at design time.I want to customize the .NET collection editor to add my Holiday class instances instead of object type.Please help me. My holiday class is very simple as follow : public class Holiday { private int month; private int day; private string reason; public Holiday(int month,int day,int reason) {...} //Properties public int Month {...} public int Day {...} public string Reason {...} } I read some articles is code project but they were very complicated.Please give me one simple tutorial link if you can. Xironix

    S S 2 Replies Last reply
    0
    • H heavenamour

      :confused:Hi every body I Wrote a calendar class that have a collection of holidays as an ArrayList. This collection is a property of my custom control that I want Add some objects of Holiday class to it at design time.I want to customize the .NET collection editor to add my Holiday class instances instead of object type.Please help me. My holiday class is very simple as follow : public class Holiday { private int month; private int day; private string reason; public Holiday(int month,int day,int reason) {...} //Properties public int Month {...} public int Day {...} public string Reason {...} } I read some articles is code project but they were very complicated.Please give me one simple tutorial link if you can. Xironix

      S Offline
      S Offline
      spif2001
      wrote on last edited by
      #2

      Read this? http://www.codeproject.com/csharp/DzCollectionEditor.asp I'm in the high-fidelity first class traveling set. And I think I need a Lear jet.

      H 1 Reply Last reply
      0
      • S spif2001

        Read this? http://www.codeproject.com/csharp/DzCollectionEditor.asp I'm in the high-fidelity first class traveling set. And I think I need a Lear jet.

        H Offline
        H Offline
        heavenamour
        wrote on last edited by
        #3

        Thanx.Yes I read this. But I can't implement it ? I can customize the CollectionEditor for my HolidayObject but the auto generation code did not created ! Serializing could not work ! :((

        1 Reply Last reply
        0
        • H heavenamour

          :confused:Hi every body I Wrote a calendar class that have a collection of holidays as an ArrayList. This collection is a property of my custom control that I want Add some objects of Holiday class to it at design time.I want to customize the .NET collection editor to add my Holiday class instances instead of object type.Please help me. My holiday class is very simple as follow : public class Holiday { private int month; private int day; private string reason; public Holiday(int month,int day,int reason) {...} //Properties public int Month {...} public int Day {...} public string Reason {...} } I read some articles is code project but they were very complicated.Please give me one simple tutorial link if you can. Xironix

          S Offline
          S Offline
          StealthyMark
          wrote on last edited by
          #4

          heavenamour wrote: I Wrote a calendar class that have a collection of holidays as an ArrayList. This collection is a property of my custom control that I want Add some objects of Holiday class to it at design time. You have to do three things: 1. Use a strongly typed Collection, derived from CollectionBase instead of an ArrayList or Array. This allows the CollectionEditor to work properly. 2. Create a custom TypeConverter for Holiday, which is capable of converting a Holiday instance to an InstanceDescriptor. This allows the code generator to generate code to instantiate Holiday objects. 3. Decorate the collection property of your custom control with the DesignerSerializationVisibility attribute. This tells the code generator to serialize the contents of your collection, rather than the collection itself. To illustrate these points:

          using System;
          using System.Collections;
          using System.ComponentModel;
          using System.Globalization;
          using System.ComponentModel.Design.Serialization;
          using System.Reflection;

          namespace Holidays
          {
          public class YourControl
          {
          private readonly HolidayCollection holidays = new HolidayCollection();

              // This attribute tells the code generator to serialize the contained items
              \[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)\]
              public HolidayCollection Holidays
              {
                  get { return holidays; }
              }
          }
          
          
          // The strongly typed collection
          // Never expose an ArrayList or an Array as a public property!
          public class HolidayCollection : CollectionBase
          {
              public int Add(Holiday item)
              { return List.Add(item); }
          
              public Holiday this\[int index\]
              {
                  get { return (Holiday)List\[index\]; }
                  set { List\[index\] = value; }
              }
          }
          
          
          // assign the converter
          \[TypeConverter(typeof(HolidayConverter))\]
          public class Holiday
          {
              public Holiday()
              {
                  this.month = -1;
                  this.day = -1;
                  this.reason = null;
              }
              
              public Holiday(int month, int day, string reason)
              {
                  // add validation logic here
                  this.month = month;
                  this.day = day;
                  this.reason = reason;
              }
          
              private int month;
              private int day;
              private string reason;
          
              public int Mo
          
          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