Solved

Define Custom Strings for Properties in the Property Grid

Posted on 2008-06-24
2
398 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

823 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