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: