spanky4_3

Hi everyone,

I'm not sure there is a way to do what I want but figure it is better to ask the question. I've inherited the ComboBox control and want to adjust the way it behaves. Basically it will show the DropDown when the control is entered/has focus and will restrict what the user types to the list of items. As such I don't want the designer to be able to adjust properties such as AutoCompleteMode and AutoCompleteSource.

I've read on the net that I should just be able to either shadow or overload this property, set it to protected and add the <Browsable(false)> attribute, however this does not work, the AutoCompleteMode property remains in the designer (I also read on the net that the property viewer uses reflection to determine what properties to show, so I guess it sees the parent property as Browsable and therefore displays it).

The other solution I saw on the net is to create a custom designer for the control, however as ComboBox has its own ComboBoxDesigner which is not Public, I cannot inherit and override methods to prevent certain properties from being displayed.

At present I've shadowed the properties, kept them Public, however the Set method does nothing. In this case the property appears in the designer however it cannot be set to anything other than the default value. This will work, however it just seems wrong to have a property listed that cannot be changed.

I hope this makes some sense and if anyone has any suggestions please let me know.

Thanks,

Mark.



Re: Windows Forms General Inherited control hide property in designer

Rong-Chun Zhang - MSFT

Hi spanky,

Don't use protected property, use the public one instead. Because the protected one will make the Property Grid use the ComboBox's DropDownStyle instead of derived class's DropDownStyle. So you code maybe something like this:

Code Snippet

namespace CBO

{

class ExComboBox : ComboBox

{

[Browsable(false)]

public new ComboBoxStyle DropDownStyle

{

get

{

return base.DropDownStyle;

}

set

{

base.DropDownStyle = value;

}

}

[Browsable(false)]

public new AutoCompleteMode AutoCompleteMode

{

get

{

return base.AutoCompleteMode;

}

set

{

base.AutoCompleteMode = value;

}

}

[Browsable(false)]

public new AutoCompleteSource AutoCompleteSource

{

get

{

return base.AutoCompleteSource;

}

set

{

base.AutoCompleteSource = value;

}

}

}

}

Hope this helps.

Regards






Re: Windows Forms General Inherited control hide property in designer

spanky4_3

Hi Rong-Chun,

Thanks for you reply, I can't believe it was that easy. I feel a bit stupid for not trying that before asking.

Thanks again,

Mark.