的WinForm的PropertyGrid集合编辑器中添加/删除按钮无效 [英] WinForm propertygrid Collection Editor Add/Remove buttons Inactive

查看:2029
本文介绍了的WinForm的PropertyGrid集合编辑器中添加/删除按钮无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是通用的PropertyGrid从几个自定义类编辑值。其中一些类都有收藏,我可以打开这些藏品没有在集合编辑器的问题不会有问题。如果集合中已包含的对象,我能够选择的对象,并对其进行编辑就没事了,但添加/删除按钮是无效的。

I am using the generic propertygrid to edit values from several custom classes. Some of these classes have collections and I can open those collections without a problem in the Collection Editor without a problem. If the collection already contains objects I am able to select those objects and edit them on the right, but the the Add/Remove buttons are inactive.

我知道一些藏品将需要自定义编辑器,因为它们是相当complicated--但其中大部分都相当简单。有没有一种简单的方法主动添加/删除按钮,这些简单的类或者我需要创建为每收集一个自定义编辑器?

I know for some of these collections are going to need a custom editor as they are quite complicated-- but most of them are quite simple. Is there an easy way active the add/remove buttons for these simple classes or do I need to create a custom editor for every collection?

推荐答案

有关添加和删除按钮被激活,你需要收集到实施非一般的的IList 的接口,以及,很明显,属性的只读必须返回

For the Add and Remove button to be enabled, you need the collection to implement the non generic IList interface, and, obviously, the property ReadOnly must return false.

请注意你需要一个明确的实现上下课,从一个类或者接口本身自IList派生只是推导(SUC为的IList<东西> )将不可以的工作。

Note you need an explicit implementation on the class, just deriving from a class or interface that itself derives from IList (suc as IList<Something>) will not work.

例如,下面是不正常:

public class MyStuffCollection : List<MyStuff>
{
}

和以下是确定的:

public class MyStuffCollection : List<MyStuff>, IList
{
}

这篇关于的WinForm的PropertyGrid集合编辑器中添加/删除按钮无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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