Solved

Define Custom Strings for Properties in the Property Grid

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

Accepted Solution

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now