Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

UserControl Dropdown Property

Status
Not open for further replies.

schwarem

Programmer
Apr 18, 2002
159
0
0
US
I am making a UserControl to be used in other Windows Forms applications. How do I make the property in the designer be a dropdown list? I've done basic properties using text and boolean values like the one below, but I want one where I define the items in the list the user can choose from.

Code:
[Bindable(true), 
            Category("HIVE"), 
            DefaultValue(0),
            Description("Specifies the maximum number of drop-down items in the combo box.")]
            property int MaxDropDownItems 
            {
                int get() 
                {
                    return this->comboBoxFocusEntity->MaxDropDownItems;
                }
            
                void set(int val) 
                {
                    this->comboBoxFocusEntity->MaxDropDownItems = val;
                }
            }
 
You can use a public enum. This should expose the enum values in the properties window at design time.
 
Code:
[COLOR=blue]public enum[/color] [COLOR=teal]MyPropertyType[/color]
{
    myValue1,
    myValue2,
    myValue3
}

[COLOR=blue]private[/color] [COLOR=teal]MyPropertyType[/color] _MyProperty;
[COLOR=blue]public[/color] [COLOR=teal]MyPropertyType[/color] MyProperty
{
    [COLOR=blue]get[/color] { [COLOR=blue]return[/color] _MyProperty; }
    [COLOR=blue]set[/color] { _MyProperty = value; }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top