Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Overriding properties in subclasses
Message
 
To
19/07/2006 14:01:24
General information
Forum:
ASP.NET
Category:
Class design
Miscellaneous
Thread ID:
01137567
Message ID:
01137760
Views:
22
Bonnie,

I've got it working and everything appears to be correct. I used a combination of your responses. This defaults to DropDownList (not bolded) and changing the property bolds it and allows it to be Reset to DropDownList.
public class caComboBox : ComboBox
{
    // Override inherited settings with new default values.
    [DefaultValue(typeof(System.Windows.Forms.ComboBoxStyle), "DropDownList")]
    new public ComboBoxStyle DropDownStyle
    {
        get
        {
            return base.DropDownStyle;
        }
        set
        {
            base.DropDownStyle = value;
        }
    }

    public caComboBox()
    {
        // Set the starting value to DropDownList.
        this.DropDownStyle = ComboBoxStyle.DropDownList;
    }
}
Thank you so much. It is easy, though not obvious. ;)
Chad

>OK, normally to get that kind of behavior, all you need is to set the DrowDownStyle in the constructor (like I already showed you) and then code like this:
>
>
>[DefaultValue(typeof(System.Windows.Forms.ComboBoxStyle), "DropDownList")]
>public override ComboBoxStyle DropDownStyle
>{
>	get
>	{
>		return base.DropDownStyle;
>	}
>	set
>	{
>		base.DropDownStyle = value;
>	}
>}
>
>
>However, for this particular property, it doesn't work. That's because you'll get an error about DropDownStyle not being a virtual property and so you can't override it.
>
>But, if you change the "override" to a "new", it will work (with the only exception that now the DefaultValue doesn't appear to be available so that you can do a "reset" in the property sheet. I don't know of any way around that.
>
>~~Bonnie
_________________________________
There are 2 types of people in the world:
    Those who need closure
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform