Re[9]: DataGrid + PropertyGrid
От: Serge2005  
Дата: 19.07.05 14:01
Оценка:
Спасибо большое ! Кое что уже стало получаться

Я взял за пример одну из чьих то реализаций
TypeConverter

    public class ConverterBool : System.ComponentModel.TypeConverter
    {
        StandardValuesCollection svc = new StandardValuesCollection(new bool[]{true, false});
        public ConverterBool(){}
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true;
        }
        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }
        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {        
            return svc;
        }
        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            if(sourceType == typeof(string))
                return true;

            return base.CanConvertFrom (context, sourceType);
        }
        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string str = value as string;
            if(str != null)
                return (str == "Истина");

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

            return base.CanConvertTo (context, destinationType);
        }
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            if(destinationType == typeof(string) && value != null)
            {
                if(value.GetType() == typeof(bool))
                {
                    bool val = (bool)value;
                    if(val)
                        return "Истина";
                    else
                        return "Ложь";
                }
            }

            return base.ConvertTo (context, culture, value, destinationType);
        }
    }



далее в классе MyPropDesc сделал типа того


public override TypeConverter Converter 
        {
            get 
            {
                if (_PropDesc.Name == "dsp_sex_name") 
                {
                    return new ConverterBool();
                } else return base.Converter;
            }
        }


В общем уже стало получаться и появились определённые понятия.

Большое Вам спасибо за помощь
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.