Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET User Control Property Value Options In Designer Mode

I am using Visual Studio 2008 | .NET 3.5 | C#. I have created an user control that has the following property: DisplayMode. DisplayMode is meant to either display a series of text boxes or a single text box.

[Browsable(true),
Category("Appearance"),
DefaultValue(DISPLAY_MODE_FIELDS),
Description("Indicates whether to display the phone number as a single text box or separate fields.")]
public string DisplayMode
{
      get { return mDisplayMode; }
      set { mDisplayMode = value; }
    }

Therefore, I want the options of the property to either be 'Fields' or 'Single'. I specified above I want to make this browsable in the designer, but how do I set those two values as options rather than knowing to specify 'Fields', 'Single', etc. in the future? Is there another attribute that I can decorate the property with to list these options out or do I need to create an enum (which works)?

Thanks in advance and please let me know if you need any other info!

like image 802
psuphish05 Avatar asked Jun 02 '09 20:06

psuphish05


3 Answers

The enum is the way to go. It will provide IntelliSense for the values in the Visual Studio HTML editor, and it will be more type-safe and easier to use in the code.

like image 50
Jeromy Irvine Avatar answered Nov 15 '22 21:11

Jeromy Irvine


Just create an Enum

In your user control -

    public enum OrientationOption
    { 
        Horizontal,
        Vertical
    }

    public OrientationOption Orientation { get; set; }

That's it ! this is how it will look like in your VS autocomplete
Auto complete options in code view

like image 41
Alex Z Avatar answered Nov 15 '22 20:11

Alex Z


I would create a enum for the DisplayMode attribute of your user control

like image 22
Michael Kniskern Avatar answered Nov 15 '22 21:11

Michael Kniskern