Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Overriding properties in subclasses
Message
De
19/07/2006 14:01:24
 
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01137567
Message ID:
01137743
Vues:
25
This message has been marked as the solution to the initial question of the thread.
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



>Bonnie,
>
>Thanks. That was one of the things I had tried, but that isn't the behavior I'm after. What I want is for the default value of the property to be DropDownList, but still be changeable at design-time by the developer. And if you right-click the property on the property sheet and click Reset, then I want it to be reset to DropDownList. I know this has to be possible and should be easy.
>
>TIA,
>Chad
>
>
>>Chad,
>>
>>If you want the DropDownStyle to always be DropDownList, then set it in the constructor of the class rather
>than try to override the property:
>>
>>using System;
>>using System.Drawing;
>>using System.Collections;
>>using System.ComponentModel;
>>using System.Windows.Forms;
>>using System.Data;
>>
>>namespace MyCompany.WinUI.MyClasses
>>{
>>    public class MyComboBox : System.Windows.Forms.ComboBox
>>    {
>>        public MyComboBox()
>>        {
>>            // Override settings with new default values in the constructor.
>>            this.DropDownStyle = ComboBoxStyle.DropDownList;
>>        }
>>    }
>>}
>>
>>
>>~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform