Click here to Skip to main content
15,892,059 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.6K   11.2K   90  
A PropertyGrid implementation showing how-to use, best practices, validation, and more.
using CustomControls.Data;

namespace CustomControls.Data
{
	public class DataListAttribute : ListAttribute, IAddNew
	{
		#region Data Members

		private readonly string _dllName;
		private readonly string _className;
		private readonly string _path;
		private readonly bool _isStatic;
		private readonly bool _addNew;
		private readonly string _eventHandler;

		#endregion

		#region Constructor
		
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="path">Path to the list of items for display in the GridComboBox</param>
		public DataListAttribute( string path )
		{
			this._path = path;
			this._isStatic = false;
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="path">Path to the list of items for display in the GridComboBox</param>
		/// <param name="allowNew">True - Allow new object to be created and added to list of items</param>
		public DataListAttribute( string path, bool allowNew )
			: this( path )
		{
			this._addNew = allowNew;
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="path">Path to the list of items for display in the GridComboBox</param>
		/// <param name="allowNew">True - Allow new object to be created and added to list of items</param>
		/// <param name="eventHandler">On Add Callback Notification Method - Must be of type delegate ObjectAddedEventHandler</param>
		public DataListAttribute( string path, bool allowNew, string eventHandler )
			: this( path, allowNew )
		{
			this._eventHandler = eventHandler;
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="dllName">The name of the dll the class belongs to</param>
		/// <param name="className">The name of the class</param>
		/// <param name="path">Path to the list of items for display in the GridComboBox</param>
		public DataListAttribute( string dllName, string className, string path )
			: this( path )
		{
			this._isStatic = true;
			this._dllName = dllName;
			this._className = className;
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="dllName">The name of the dll the class belongs to</param>
		/// <param name="className">The name of the class</param>
		/// <param name="path">Path to the list of items for display in the GridComboBox</param>
		/// <param name="allowNew">True - Allow new object to be created and added to list of items</param>
		public DataListAttribute( string dllName, string className, string path, bool allowNew )
			: this( dllName, className, path )
		{
			this._addNew = allowNew;
		}

		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="dllName">The name of the dll the class belongs to</param>
		/// <param name="className">The name of the class</param>
		/// <param name="path">Path to the list of items for display in the GridComboBox</param>
		/// <param name="allowNew">True - Allow new object to be created and added to list of items</param>
		/// <param name="eventHandler">On Add Callback Notification Method - Must be of type delegate ObjectAddedEventHandler</param>
		public DataListAttribute( string dllName, string className, string path, bool allowNew, string eventHandler )
			: this( dllName, className, path, allowNew )
		{
			this._eventHandler = eventHandler;
		}

		#endregion

		#region Properties

		/// <summary>
		/// Get/Set for ClassName
		/// </summary>
		public string ClassName
		{
			get { return ( _className ); }
		}

		/// <summary>
		/// Get/Set for DllName
		/// </summary>
		public string DllName
		{
			get { return ( _dllName ); }
		}

		/// <summary>
		/// Get for Path
		/// </summary>
		public string Path
		{
			get { return ( _path ); }
		}

		/// <summary>
		/// Get for IsStatic
		/// </summary>
		public bool IsStatic
		{
			get { return ( _isStatic ); }
		}

		/// <summary>
		/// Get for AddNew
		/// </summary>
		public bool AddNew
		{
			get { return ( _addNew ); }
		}

		/// <summary>
		/// Get for EventHandler
		/// </summary>
		public string EventHandler
		{
			get { return ( _eventHandler ); }
		}

		#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