I have a System.Windows.Forms.PropertyGrid
with different types of values. For a specific item, I want to show a list of useful values to choose from. The user may also type a new value. Something similar to a traditional dropdown combobox:
So far, I have my own System.ComponentModel.TypeConverter
, but I can't figure out how to get both the dropdown with suggested values and the possibility to edit the value directly. Please help!
To make the text portion of a ComboBox non-editable, set the DropDownStyle property to "DropDownList". The ComboBox is now essentially select-only for the user. You can do this in the Visual Studio designer, or in C# like this: stateComboBox.
You can accomplish this by implementing your own UITypeEditor.
I recommend reading Getting the Most Out of the .NET Framework PropertyGrid Control. In particular, the section titled Providing a Custom UI for Your Properties walks through how to make a custom control for a specific property.
It is easy. In your own StringConverter
return false
for GetStandardValuesExclusive
and that is it.
Look here:
internal class cmbKutoviNagiba : StringConverter
{
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return FALSE; // <----- just highlight! remember to write it lowecase
}
public override TypeConverter.StandardValuesCollection GetStandardValues(
ITypeDescriptorContext context)
{
string[] a = { "0", "15", "30", "45", "60", "75", "90" };
return new StandardValuesCollection(a);
}
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
}
I wrote FALSE
in capital letters, just to make you easyer to see it. Please put it in small letters :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With