Click here to Skip to main content
15,896,063 members
Articles / Desktop Programming / Windows Forms

DataGridViewColumn Hosting MaskedTextBox

Rate me:
Please Sign up or sign in to vote.
4.55/5 (21 votes)
12 May 2008CPOL3 min read 222.1K   7.9K   68  
How to host a MaskedTextBox in a DataGridViewColumn
/**********************************
 * Title:       Description Attribute Called from a Referenced Property's Description
 * Author:      Juergen Thomas
 * Email:       post@vs-polis.de
 * Environment: WinXP, NET 2.0
 * Keywords:    ReferencedDescriptionAttribute, Reference, DescriptionAttribute,
 *              Description, Attribute
 * Description: An article how to show a description attribute referencing 
 *              the description attribute of another class and a specific property
 * Section      General Programming
 * SubSection   Programming Tips - General
 * 
 * Example
 * -------
 * [ReferencedDescription(typeof(System.Windows.Forms.MaskedTextBox), "Mask")]
 * 
 * This attribute calls the description of Mask property in MaskedTextBox class.
**********************************/

#region Usings
using System;
using System.ComponentModel;
#endregion

namespace JThomas.Extensions
{
	
	/// <summary>
	/// ReferencedDescriptionAttribute shows the description of a specific property
	/// in an existing class (the "referenced type").
	/// </summary>
	public class ReferencedDescriptionAttribute : DescriptionAttribute
	{
		
		public ReferencedDescriptionAttribute(Type referencedType, string propertyName)
		{
			//	default description
			string result = "Referenced description not available";
			
			//	gets the properties of the referenced type
			PropertyDescriptorCollection properties 
				= TypeDescriptor.GetProperties(referencedType);
			
			if (properties != null) {

				// gets a PropertyDescriptor to the specific property.
				PropertyDescriptor property = properties[propertyName];
				if (property != null) {
					//  gets the attributes of the required property
					AttributeCollection attributes = property.Attributes;
					
					// Gets the description attribute from the collection.
					DescriptionAttribute descript
						= (DescriptionAttribute)attributes[typeof(DescriptionAttribute)];
					
					// register the referenced description
          if (!String.IsNullOrEmpty(descript.Description))
						result = descript.Description;
 				}

			}
			DescriptionValue = result;
			
		}
		
	}
	
}

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
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions