DanMayer Rate me:. Please Sign up or sign in to vote. Illustrates simple PropertyGrid editing of class properties using TypeConverter. Download source files - 7 Kb Introduction There have been plenty of articles here on CodeProject discussing advanced use the PropertyGrid control.
Problem: default view of a class property is the namespace. In other words, we want to change the PropertyGrid display on the left to the friendlier one on the right: Default view With type converter To understand how to go from one to the other, let's look at the simple sample.
Copy Code. A list of licenses authors might use can be found here. DanMayer Web Developer. PeterFritzen Mar Frank W. Wu Jun Go to top. Layout: fixed fluid. Web Developer. United States. First Prev Next. Member CanConvertTo Returns true if the indicated type is string to indicate that the converter can convert a StreetAddress into a string. ConvertFrom Converts a string into a StreetAddress. ConvertTo Converts a StreetAddress into a string.
GetProperties Returns a collection of type descriptors to tell the PropertyGrid about the properties that the StreetAddress supports. ToString ; return base. This entry was posted in attributes , controls , OOP and tagged attribute , attributes , C , C programming , category , controls , description , example , example program , OOP , PropertyGrid , type converter , TypeConverter , Windows Forms programming.
Bookmark the permalink. April 4, at pm. Really great article! Excactly what I was looking for. Just a clear description of what to do when using property grids with own types.
Thank you very much for sharing! The PersistenceMode attribute tells how to persist it. The default value is Attribute which means it will add all the properties as attributes using the property name hyphen sub-property name syntax.
Here is an example:. By using the InnerProperty value you tell it to make it a sub-tag when persisting it. Here is an example of that syntax:. There are many more control attributes you can apply.
But that goes beyond this article. Here is the code snippet for the DesignerSerialization and PersistenceMode attributes:. Please see the attached sample for a complete working control.
It allows you to set the value of the GPS location property in the property browser and then outputs it when rendering the control.
Type converters are an important part of the Visual Studio. NET designer and property browser as well as the view state management. As long as you use standard types there is no need to write your own type converter. But when you create your own complex types you need to implement your own type converters.
This article explains how to implement your own type converters and how to associate those type converters with your complex types. I want to hear if you have learned something new. Contact me if you have questions about this topic or article. This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
Sign in Email. Forgot your password? Search within: Articles Quick Answers Messages. Tagged as. Stats K views. Type converters, your friendly helpers! Klaus Salchner Canada Rate me:. Please Sign up or sign in to vote. Any time you developed a web form or Windows form using the Visual Studio. As the name already states, type converters are used to convert from one type to another.
Download source files - Kb Introduction You may not have written yet your own type converter. Where are type converters used? How do type converters work? CanConvertTo - Passes along the required destination type, for example, type of string.
The method returns true if it can convert to that type otherwise false. ConvertTo - Gets passed along the type to convert, the destination type and the culture info to use during the type conversion. This method then returns the converted type. CanConvertFrom - Passes along the source type, for example, the type of string. The method returns true if it can convert from that type back to your type.
Otherwise it returns false. ConvertFrom - Gets passed along the type to convert from and the culture info to use during the type conversion.
This method returns then the converted type. Walk through a sample type converter The attached sample application defines three complex types - GPSLocation , Latitude and Longitude. Copy Code. A list of licenses authors might use can be found here.
Klaus Salchner Canada. Chief Technology Officer. Experienced technology leader who is passionate about building cloud and enterprise based products. Building an innovative and modern cloud product is a people business which requires to assemble a team of passionate and continuously improving technologists, establishing a vision and framework to buy into, and then let your team execute and drive that product vision.
Ship frequently, build a strong feedback loop with your customers and partners and continuously iterate till you get it right. I am a seasoned executive which has more then twenty-five years of experience running product development organizations around the globe. Managed many initiatives across organizational boundaries and has often been called upon by the CEO, COO or SVP to manage teams, projects or systems from crisis to success.
Delivered numerous innovations which resulted in millions of dollar revenue and has been featured in several case studies by Microsoft. Active contributor in the online technical community. You can read more about the four Product leadership experiences which I have demonstrated over my career and which I deeply care about at my LinkedIn profile. Thorsten Bruning 1-Sep David Veeneman Apr Member 8-Oct Mike Ellison Apr WillemM Apr Doubin Apr Go to top.
Layout: fixed fluid. First Prev Next. Type converters are about to be my enemies Jaime Stuardo - Chile 9-Mar Jaime Stuardo - Chile. There is something breaking my head. GetConverter property ; But returned converter is System.
TypeConverter and not Converters. DevicesTypeConverter, so I cannot call any type converter method. Any idea how to solve this? Thanks Jaime. My vote of 5 Thorsten Bruning 1-Sep Thorsten Bruning. Great - inspired me for my first article here, thanks! Clarification regarding TypeConverter milanboi 1-Aug Help me with the code juliesamy Feb
0コメント