C # display custom properties in the propertyGrid Control

Source: Internet
Author: User

C # display custom properties in the propertyGrid Control

In the previous article (Address: C # dynamically changing the properties displayed by the object in PropertyGrid during design), you can see:

The display of custom attributes is problematic. How can I modify them?

The Code is as follows:

 

public class PropertyDisplayConverterr
 
   : ExpandableObjectConverter where T : IDisplay    {        public override bool CanConvertTo(ITypeDescriptorContext context, System.Type destinationType)        {            if (destinationType == typeof(T))                return true;            return base.CanConvertTo(context, destinationType);        }        // This is a special type converter which will be associated with the T class.        // It converts an T object to string representation for use in a property grid.        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, System.Type destinationType)        {            if (destinationType == typeof(System.String) && value is T)            {                return ((IDisplay)value).GetDisplayString();            }            return base.ConvertTo(context, culture, value, destinationType);        }    }
 
Interface:

 

 

Public interface IDisplay {////// Obtain the displayed string //////
 String GetDisplayString ();}
Modify the entity class as follows:

 

 

[TypeConverterAttribute (typeof (PropertyDisplayConverterr
 
  
)] Public class IdentityColumnEntity: IDisplay {private bool isIncrementColumn ;///
  /// Whether it is an auto-increment column ///[Browsable (true)] [Category (basic)] [DisplayName (whether it is an auto-incrementing column)] [ReadOnly (false)] [DefaultValue (false)] public bool IsIncrementColumn {set {isIncrementColumn = value;} get {return isIncrementColumn;} private Int64 identityIncrement ;///
  /// ID increment ///[Browsable (true)] [Category (basic)] [DisplayName (ID increment)] [ReadOnly (false)] [Description (ID increment attribute specifies the value added based on the existing largest row id value when Microsoft SQL Server generates the id value for the inserted row. The ID increment must be a non-zero integer with the number of digits equal to or less than 10.)] Public Int64 IdentityIncrement {set {identityIncrement = value;} get {return identityIncrement;} private Int64 ident_Seed ;///
  /// Identify the seed ///[Browsable (true)] [Category (basic)] [DisplayName (identification seed)] [ReadOnly (false)] [Description (indicating the initial row value of the ID column. The seed must be an integer with the number of digits equal to or less than 10.)] Public Int64 Ident_Seed {set {ident_Seed = value;} get {return ident_Seed;} public string GetDisplayString () {if (this = null | this. identityIncrement = 0) {return does not set auto-incrementing column information;} return String. format (ID seed: {0}; Id increment: {1}, this. ident_Seed, this. identityIncrement );}}
 
The effect is as follows:

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.