我有一个很久以前从某个地方抓取的自定义控件:
public class NotifyingCollectionEditor : CollectionEditor
{
// Define a static event to expose the inner PropertyGrid's PropertyValueChanged event args...
public delegate void MyPropertyValueChangedEventHandler(object sender, PropertyValueChangedEventArgs e);
public static event MyPropertyValueChangedEventHandler ElementChanged;
// Inherit the default constructor from the standard Collection Editor...
public NotifyingCollectionEditor(Type type) : base(type) { }
// Override this method in order to access the containing user controls from the default Collection Editor form or to add new ones...
protected override CollectionForm CreateCollectionForm()
{
// Getting the default layout of the Collection Editor...
CollectionForm collectionForm = base.CreateCollectionForm();
Form frmCollectionEditorForm = collectionForm as Form;
TableLayoutPanel tlpLayout = frmCollectionEditorForm.Controls[0] as TableLayoutPanel;
if (tlpLayout != null)
{
// Get a reference to the inner PropertyGrid and hook an event handler to it.
if (tlpLayout.Controls[5] is PropertyGrid)
{
PropertyGrid propertyGrid = tlpLayout.Controls[5] as PropertyGrid;
propertyGrid.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid_PropertyValueChanged);
}
}
return collectionForm;
}
void propertyGrid_PropertyValueChanged(object sender, PropertyValueChangedEventArgs e)
{
// Fire our customized collection event...
var evt = NotifyingCollectionEditor.ElementChanged;
if (evt != null)
evt(this, e);
}
}
当集合中的一个已编辑项目发生更改时,它曾经触发事件,但即使在此集合中添加或删除了某些项目,我也需要它触发。
目前,除了比较创建表单时元素的数量之外,我没有其他想法,并且它已经接近了。
但是我怎样才能访问那个编辑过的集合来获得它的Count
价值呢?
我试图访问propertyGrid.SelectedObject
,但它是空的,即使它不是,我认为有收藏项,而不是收藏。