Здравствуйте, Алексей Одинцов, Вы писали:
АО>TypeConvertor
В MSDN есть примеры использования TypeConverter для класса.
В этом случае объект становится редактируемым в PropertyGride.
Но, мне нужно редактировать Property.
Вот фрагмент кода
public class MyDateEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService wfes;
System.Windows.Forms.MonthCalendar ca = new System.Windows.Forms.MonthCalendar();
Component cmp = (Component) provider.GetType().GetProperty("Component").GetGetMethod().Invoke(provider, new object[0]);
wfes = (IWindowsFormsEditorService) provider.GetService(typeof(IWindowsFormsEditorService));
wfes.DropDownControl(ca);
wfes.CloseDropDown();
return ca.SelectionStart;
}
}
В описании свойства указываем свой едитор
[EditorAttribute(typeof(MyDateEditor), typeof(UITypeEditor))]
public DateTime MyDate2
{
get {return _myDate2;}
set {_myDate2 = value;}
}
если в методе EditValue обратиться к параметру context, то можно добраться до
TypeConverter: context.PropertyDescriptor.Converter
он возвращает System.ComponentModel.StringConverter
А, как ему подставить свой конвертер?
В интернете я не нашел ни одного примера.