PropertyGrid UITypeEditor禁用单元格编辑 [英] PropertyGrid UITypeEditor Disable cell edit

查看:252
本文介绍了PropertyGrid UITypeEditor禁用单元格编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个属性网格,并且其中一个属性使用

I have a property grid and one of the properties uses a UITypeEditor to edit the value (on a form).

但是该属性仍然是可编辑的,我不希望如此.有没有办法做到这一点?我查看了类似的问题 Propertygrid UIEditor禁用了通过键盘进行值编辑,但是它不能解决我的问题,因为解决方案是使用TypeConverter的简单下拉列表.

However the property is still editable, which I do not want. Is there a way to do this? I looked at this similar question Propertygrid UIEditor disabling value editing through Keyboard but it does not solve my problem as the solution is a simple dropdown list using TypeConverter.

推荐答案

一种解决方案是声明

One solution is to declare a TypeConverter that does ... nothing, something like this:

这是您要编辑的课程:

public class MyClass
{
    [Editor(typeof(MyClassEditor), typeof(UITypeEditor))]
    [TypeConverter(typeof(MyConverter))]
    public string MyProperty { get; set; }
}

这是自定义UITypeEditor:

This is the custom UITypeEditor:

public class MyClassEditor : UITypeEditor
{
    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
        return UITypeEditorEditStyle.Modal;
    }

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
        MessageBox.Show("press ok to continue");
        return "You can't edit this";
    }
}

这是著名的转换器,我花了几天的时间来写:

This is the famous converter that took me days to write:

// this class does nothing on purpose
public class MyConverter : TypeConverter
{
}

这篇关于PropertyGrid UITypeEditor禁用单元格编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆