How to add editable combobox to System.Windows.Forms.PropertyGrid?

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 can also enter a new value. Something like a traditional drop down menu:

enter image description here

So far, I have my own System.ComponentModel.TypeConverter , but I can’t figure out how to get a drop-down menu with suggested values ​​and the ability to directly edit the value. Please, help!

+6
source share
2 answers

You can accomplish this by running your own UITypeEditor .

I recommend reading Get the most out of the .NET Framework PropertyGrid Control . In particular, a section entitled Providing a user interface for your properties describes how to create a custom control for a specific property.

+6
source

It is easy. In your StringConverter return false for GetStandardValuesExclusive , and that’s all.

Look at 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 capital letters, just to make it easier for you to see it. Please enter small letters :)

+4
source

Source: https://habr.com/ru/post/911216/


All Articles