Answer the question
In order to leave comments, you need to log in
How to easily organize a Combobox in a Propertygrid (c#)?
Of course, I found an article on Habré, but I can’t perceive such a large amount of new information (((
habrahabr.ru/post/78024
While this works and in the Propertygrid I see this property and can change:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication13
{
[TypeConverter(typeof(ExpandableObjectConverter))]
class Vec2
{
[DisplayName("Координата x"), Description("Координата x"), Category("Координаты")]
public float x { get; set; }
[DisplayName("Координата y"), Description("Координата y"), Category("Координаты")]
public float y { get; set; }
public Vec2(float x, float y)
{
this.x = x;
this.y = y;
}
}
}
Answer the question
In order to leave comments, you need to log in
For example, you have an object with a property of type string and you want to be able to select a new value for this property from a drop-down list through the PropertyGrid. It looks like this:
using System;
using System.ComponentModel;
public class MyClass
{
[TypeConverter(typeof(EnumConverter))]
public string stringProperty {get; set;}
public MyClass()
{
stringProperty = EnumConverter.ALT1;
}
class EnumConverter : TypeConverter
{
public const string ALT1 = "Альтернатива1";
public const string ALT2 = "Альтернатива2";
public const string ALT3 = "Альтернатива3";
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {return true; }
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) {return true; }
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
return new StandardValuesCollection(new[] {ALT1, ALT2, ALT3 });
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question