Click here to Skip to main content
11,928,740 members (56,229 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked

Show properties of a class on a PropertyGrid

, 20 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
How to show properties of a class on a PropertyGrid.

When developing user controls, usually we use Booleans, Integers, Strings, etc.. as data types of the attributes of the control. But sometimes, we have to use structures or other classes as attributes. When we use those, we should be able to change or browse the attributes of those structures or classes.

Open Visual Studio IDE and create a new Windows Forms Application type project.

Add a new class and name it MyCustomClass. And define two properties: an integer and a string type.

public class MyCustomClass {

    public int MyIntProperty { get; set; }
    public string MyStringProperty { get; set; }

    public override string ToString() {
        return "...";

**Please note that I have overridden the ToString method. Because this is what will be shown on the property grid when the properties are collapsed.

Now add a new user control to the project and name it MyCutomUsercontrol. And create three properties: an integer, string, and MyCustomClass. And use the [TypeConverter(typeof(ExpandableObjectConverter))] attribute on the third property. The syntax should be:

public partial class MyCutomUsercontrol : UserControl {
    public MyCutomUsercontrol() {

    private MyCustomClass _MyCustomClass = new MyCustomClass();

    public int Property1 { get; set; }
    public string Property2 { get; set; }

    public MyCustomClass Property3 {
        get {
            return _MyCustomClass;
        set {
            _MyCustomClass = value;

Now build the solution. And add it to a Windows Form. And on the property grid, you can see your custom control's properties.



This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Manjuke Fernando
Technical Lead Air Liquide Industrial Services (Singapore)
Singapore Singapore
I have been in software industry for more than 8 years. I have developed different type of software using different languages. Many of them are database related (both web & window based), SQL being as the back end most of the time. Up-to-date I have knowledge in languages such as C#, VB.Net, T-SQL, JAVA, VB6 & C++, making C# the most proficient of all. Also I have worked using different technologies like ASP.Net, SharePoint, Crystal Reports (But I really hate designing reports) & MS SQL Server and have involved in designing & developing software for major companies like FedEx, Softlogic Holdings, IronOne Technologies & Brandix. Currently I am working as a Tech Lead in Singapore.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151126.1 | Last Updated 20 Oct 2011
Article Copyright 2011 by Manjuke Fernando
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid