WinForm propertygrid Collection Editor Add/Remove buttons Inactive

穿精又带淫゛_ 提交于 2019-12-11 11:47:30

问题


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.

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?


回答1:


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.

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.

For example, the following is not ok:

public class MyStuffCollection : List<MyStuff>
{
}

and the following is ok:

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


来源:https://stackoverflow.com/questions/15167443/winform-propertygrid-collection-editor-add-remove-buttons-inactive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!