Solved

Define Custom Strings for Properties in the Property Grid

Posted on 2008-06-24
2
401 Views
Last Modified: 2013-12-16
Hello Experts,

I am building a .NET control using C# 2008, my control contains some composite properties that has predefined values that are, and those predefines values are set from enumeration that are already defined in my control.

The Properties window display the enum values for the property of that enum type. So if you declare the following

Public enum MyEnum
{
    Value1 = 0,
    Value2 = 1,
    Value3 = 2
}

Then declare a property of that enum type

Public MyEnum MyProperty
{
Get
{
}
Set
{
}
}

The values of the enum (Value1, Value2, Value3) appear in a combo next to the property name in the Property Window

My problem is that I do not want the property to display the enum values. I want the property to display my own named value such as
0  Value 1
1  Value 2
2  Value 3
Instead of Value1, Value2, Value3

How can I make the property show such values in Visual Studio Property Window?

I know that in ActiveX controls we use IPerPropertyBrowser interface, but how to do it in .net C#?

I cant implement this interface because it deals with dispatch IDs ( a COM thing)

Thanks in Advance
0
Comment
Question by:ASD-JO
2 Comments
 
LVL 18

Expert Comment

by:philipjonathan
ID: 21856326
Would it help if you initialise the default value in the control's constructor:

public class MyControl
{
...
  public MyControl()
  {
    MyProperty = MyEnum.Value1;
  }
...
}
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 21856754
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question