Customizing .NET Collection Editor
-
: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
-
: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
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.
-
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.
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 ! :((
-
: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
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 customTypeConverter
for Holiday, which is capable of converting a Holiday instance to anInstanceDescriptor
. This allows the code generator to generate code to instantiate Holiday objects. 3. Decorate the collection property of your custom control with theDesignerSerializationVisibility
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