Re: и cнова EventTab
От: Zegee Украина  
Дата: 22.11.05 15:49
Оценка:
Здравствуйте, nauro, Вы писали:

N>сделал я свой таб в PropertyGrid следующим образом.

N>есть 3 класа которые мне в этом помогли: ...

N>Вот, но во-первых, я немогу ничего редактировать в EventTab-е. Во вторых я немогу узнать какой event я сейчас редактирую...


Не знаю актуален ответ или нет. Надо переопределить PropertyDescriptor.Converter в классе EventPropertyDescriptor

например

public override TypeConverter Converter
{
get
{
if (converter == null)
{
converter = new EventConverter(evDesc);
}
return converter;
}
}

Пример самого конвертера (этот класс используется студией)

private class EventConverter : TypeConverter
{

private EventDescriptor evt;

public EventConverter(EventDescriptor evt)
{
this.evt = evt;
}

public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}

public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}

public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value != null)
{
if (!(value is string))
{
return base.ConvertFrom(context, culture, value);
}
if (((string) value).Length == 0)
{
return null;
}
}
return value;
}

public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType != typeof(string))
{
return base.ConvertTo(context, culture, value, destinationType);
}
if (value != null)
{
return value;
}
return string.Empty;
}

public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
string[] textArray1 = null;
if (context != null)
{
IEventBindingService service1 = (IEventBindingService) context.GetService(typeof(IEventBindingService));
if (service1 != null)
{
ICollection collection1 = service1.GetCompatibleMethods(this.evt);
textArray1 = new string[collection1.Count];
int num1 = 0;
foreach (string text1 in collection1)
{
textArray1[num1++] = text1;
}
}
}
return new TypeConverter.StandardValuesCollection(textArray1);
}

public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return false;
}

public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}



}
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.