我正在编写的应用程序中使用 PropertyGrid,以允许用户查看和有时编辑我的对象的实例。有时用户可能会以读/写模式打开文件,他们可以通过属性网格对文件进行更改。在其他情况下,他们可能会以只读模式打开文件,并且不应通过 PropetyGrid 对对象进行任何更改。我的类还具有通过实现 ICustomTypeDescriptor 返回的动态属性。这就是为什么我真的想利用 PropertyGrid 控件的内置灵活性。
似乎没有一种简单的方法可以将 Property-grid 设置为只读模式。如果我禁用 PropertyGrid,这也会阻止用户滚动列表。所以我认为最好的方法是在运行时将 ReadOnlyAttributes 添加到属性中。还有其他方法吗?