PropertyGrid集合编辑:我怎么知道集合何时被更改? [英] PropertyGrid collection editing: how can I know when collection been changed?

查看:206
本文介绍了PropertyGrid集合编辑:我怎么知道集合何时被更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试编辑PropertyGrid中我自己的对象的集合。但是,在"收集编辑器"中编辑集合之后,我从未接受


PropertyValueChanged事件。对话框并按确定。



如果我正在编辑对象数组,我会收到PropertyValueChanged事件。



我需要知道何时更改了集合,以便我可以保存它。



我尝试了什么:


1)使用对象数组。我得到PropertyValueChanged通知,可以保存数据。但我无法使用ICustomTypeDescriptor,无法在PropertyGrid中很好地显示我的集合。我不能从数组等继承。



2)创建并使用我自己的集合,继承自List<> ;,如示例中所述


http://www.codeproject.com/cs/miscctrl/customizingcollectiondata.asp


它显示的东西很好,但我从来没有收到PropertyValueChanged通知,也无法保存集合



3)我试图创建一个继承的集合来自CollectionBase或来自IList<>。尝试手动实现所有Add / Insert / Remove方法,并在集合中发生更改时触发我自己的事件。不幸的是,PropertyGrid几乎在任何操作上调用Clear()和数百个Add(),比如打开"Collection Editor"。对话框或按下"确定"后甚至是"取消"按钮



请帮助我!!!



这里是示例代码:






解决方案

困扰我的是:Property Grid知道什么样的集合已被更改并重新绘制自己如果我添加


[ RefreshProperties RefreshProperties .All)]



属性到colleciton的属性如



< p align = left> EmployeeCollection employees = new EmployeeCollection ();


[ RefreshProperties RefreshProperties .All)]


public EmployeeCollection 员工


{


get { return 员工; }


}



Property Grid如何知道它?我打赌他只是订阅了"Ok"。 "集合编辑器"中的按钮按下事件。
但是如何订阅该事件?当用户在集合编辑器中单击"确定"按钮时如何通知?


 

I'm trying to edit collection of my own objects in the PropertyGrid. But I never reveive

PropertyValueChanged event after I edit collection in "Collection Editor" dialog and press Ok.

 

If I'm editing an array of objects I do receive PropertyValueChanged event.

 

I need to know when collection been changed so I can save it.

 

What I tried:

1) use array of objects. and I do get PropertyValueChanged notification and can save data. But I can not use ICustomTypeDescriptor, can not show my collection nicely in PropertyGrid. I can not inherit from array etc.

 

2) create and use my own collection, inherited from List<>, like described in example 

http://www.codeproject.com/cs/miscctrl/customizingcollectiondata.asp

it shows stuff nicely, but I never receive PropertyValueChanged notification and can not save collection

 

3) I tried to create a collection inherited from CollectionBase or from IList<>. Attempt was to implement all Add/Insert/Remove methods by hand and fire my own event when something changed in collection. Unfortunately, PropertyGrid call Clear() and hundreds of Add() on almost any operation, like opening "Collection Editor" dialog or after pressing "Ok" or even "Cancel" button

 

Please help me!!!

 

here is sample code:

 

解决方案

what bother me is: Property Grid knows somehow what collection have been changed and re-draws itself if I add

[RefreshProperties(RefreshProperties.All)]

 

attribute to the colleciton's property like

 

EmployeeCollection employees = new EmployeeCollection();

[RefreshProperties(RefreshProperties.All)]

public EmployeeCollection Employees

{

    get { return employees; }

}

 

How does Property Grid knows it? I bet he just subscribe to "Ok" button pressed event in 'Collection Editor".
But how can I subscribe to that event? How Can I be Notified when user clicked Ok button in Collection Editor?


这篇关于PropertyGrid集合编辑:我怎么知道集合何时被更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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