Click here to Skip to main content
15,886,362 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.4K   11.2K   90  
A PropertyGrid implementation showing how-to use, best practices, validation, and more.
using System.Collections;
using System.Collections.Generic;
using DataModel.CarModel.Cars;
using DataModel.CarModel.Wheels;
using DataModel.CarModel.Wheels.Falken;
using DataModel.CarModel.Wheels.Kumho;

namespace CarApplication
{
	public class SupplyStore
	{
		#region Constants

		public enum SupplyParts
		{
			Cars,
			Wheels
		}

		#endregion

		#region Data Members

		private readonly SortedList<object, IList> _supplies;
		private readonly List<IList> _suppliesArray;
		private static SupplyStore _instance;

		#endregion

		#region Constructor

		/// <summary>
		/// Constructor
		/// </summary>
		public SupplyStore()
		{
			_supplies = new SortedList<object, IList>();
			_suppliesArray = new List<IList>();
		}

		#endregion

		#region Properties

		/// <summary>
		/// Get/Set for Instance
		/// </summary>
		public static SupplyStore Instance
		{
			get
			{
				if ( _instance == null )
				{
					_instance = new SupplyStore();
					LoadSupplies();
				}

				return ( _instance );
			}
		}

		/// <summary>
		/// Get/Set for Supplies
		/// </summary>
		public SortedList<object, IList> Supplies
		{
			get { return ( _supplies ); }
		}

		/// <summary>
		/// Get/Set for Supplies
		/// </summary>
		public List<IList> SuppliesArray
		{
			get { return ( _suppliesArray ); }
		}

		/// <summary>
		/// 
		/// </summary>
		public List<Wheel> Wheels
		{
			get { return ( _instance.Supplies["Wheels"] as List<Wheel> ); }
		}

		/// <summary>
		/// 
		/// </summary>
		public List<Car> Cars
		{
			get { return ( _instance.Supplies["Cars"] as List<Car> ); }
		}

		#endregion

		#region Methods - Private

		/// <summary>
		/// 
		/// </summary>
		private static void LoadSupplies()
		{
			List<Wheel> wheels = new List<Wheel>();
			wheels.Add( new FalkenZE912() );
			wheels.Add( new FalkenZiexSTZ04() );
			wheels.Add( new Kumho716HP4() );
			wheels.Add( new KumhoEcsta711() );

			List<Car> cars = new List<Car>();
			cars.Add( new Cobalt() );
			cars.Add( new Corvett() );
			cars.Add( new Implala() );

			_instance.Supplies.Add( "Wheels", wheels );
			_instance.Supplies.Add( "Cars", cars );

			_instance.SuppliesArray.Add( cars );
			_instance.SuppliesArray.Add( wheels );
		}

		#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