Click here to Skip to main content
15,895,746 members
Articles / Programming Languages / C#

Property Grid - Dynamic List ComboBox, Validation, and More

Rate me:
Please Sign up or sign in to vote.
4.57/5 (20 votes)
25 Sep 2009CPOL17 min read 167.8K   11.2K   90  
A PropertyGrid implementation showing how-to use, best practices, validation, and more.
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using CustomControls.ComboBox;
using CustomControls.Data;
using DataModel.CarModel;
using DataModel.CarModel.Cars;
using DataModel.CarModel.Wheels;

namespace CarApplication.View
{
	public class ViewCar
	{
		#region Data Members

		private readonly Car _car;

		#endregion

		#region Constructor

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="car"></param>
		public ViewCar( Car car )
		{
			_car = car;
		}

		#endregion

		#region Properties

		/// <summary>
		/// Get/Set for Wheel
		/// </summary>
		[Editor( typeof( ListGridComboBox ), typeof( UITypeEditor ) )]
		[DataList( "CarApplication", "CarApplication.SupplyStore", "Instance.Wheels", false, "OnAddedEventHandler" )]
		[CategoryAttribute( "Auto" ), DescriptionAttribute( "Description of Wheel" ), DisplayName( "SupplyStore.Instance.Wheels" )]
		public Wheel Wheel
		{
			get { return ( _car.Wheel ); }
			set { _car.Wheel = value; }
		}

		/// <summary>
		/// Get/Set for Wheel
		/// </summary>
		[Editor( typeof( ListGridComboBox ), typeof( UITypeEditor ) )]
		[DataList( "CarApplication", "CarApplication.SupplyStore", "Instance.Supplies[Wheels]", false, "OnAddedEventHandler" )]
		[CategoryAttribute( "Auto" ), DescriptionAttribute( "Description of Wheel" ), DisplayName( "SupplyStore.Instance.Supplies[Wheels]" )]
		public Wheel Wheel2
		{
			get { return ( _car.Wheel ); }
			set { _car.Wheel = value; }
		}

		/// <summary>
		/// Get/Set for Wheel
		/// </summary>
		[Editor( typeof( ListGridComboBox ), typeof( UITypeEditor ) )]
		[DataList( "CarApplication", "CarApplication.SupplyStore", "Instance.SuppliesArray[1]" )]
		[CategoryAttribute( "Auto" ), DescriptionAttribute( "Description of Wheel" ), DisplayName( "SupplyStore.Instance.SuppliesArray[1]" )]
		public Wheel Wheel3
		{
			get { return ( _car.Wheel ); }
			set { _car.Wheel = value; }
		}

		/// <summary>
		/// Get/Set for Wheel
		/// </summary>
		[Editor( typeof( ListGridComboBox ), typeof( UITypeEditor ) )]
		[DataList( "CarApplication", "CarApplication.SupplyStore", "Instance.SuppliesArray[CarApplication.SupplyStore+SupplyParts.Wheels,CarApplication]" )]
		[CategoryAttribute( "Auto" ), DescriptionAttribute( "Description of Wheel" ), DisplayName( "SupplyStore.Instance.SuppliesArray[SupplyParts.Wheels]" )]
		public Wheel Wheel4
		{
			get { return ( _car.Wheel ); }
			set { _car.Wheel = value; }
		}

		/// <summary>
		/// Get/Set for Engine
		/// </summary>
		[CategoryAttribute( "Auto" ), DescriptionAttribute( "Description of " ), DisplayName( "" )]
		public Engine Engine
		{
			get { return ( _car.Engine ); }
			set { _car.Engine = value; }
		}

		/// <summary>
		/// Get/Set for BodyColor
		/// </summary>
		[CategoryAttribute( "Auto" ), DescriptionAttribute( "Description of " ), DisplayName( "" )]
		public Color BodyColor
		{
			get { return ( _car.BodyColor ); }
			set { _car.BodyColor = value; }
		}

		/// <summary>
		/// Get/Set for InteriorColor
		/// </summary>
		[CategoryAttribute( "Auto" ), DescriptionAttribute( "Description of " ), DisplayName( "" )]
		public Color InteriorColor
		{
			get { return ( _car.InteriorColor ); }
			set { _car.InteriorColor = value; }
		}

		/// <summary>
		/// Get/Set for BodyStyle
		/// </summary>
		[CategoryAttribute( "Auto" ), DescriptionAttribute( "Description of " ), DisplayName( "" )]
		public BodyStyle BodyStyle
		{
			get { return ( _car.BodyStyle ); }
			set { _car.BodyStyle = value; }
		}

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Webbert Solutions
United States United States
Dave is an independent consultant working in a variety of industries utilizing Microsoft .NET technologies.

Comments and Discussions