Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to fire delete event for a Item of extended BindingList when a PropertyGrid delete this item?
    text
    copied!<p>The problem is that, I use this extended <code>BindingList</code></p> <pre><code>public class RemoveItemEventArgs : EventArgs { public Object RemovedItem { get { return removedItem; } } private Object removedItem; public RemoveItemEventArgs(object removedItem) { this.removedItem = removedItem; } } public class MyBindingList&lt;T&gt; : BindingList&lt;T&gt; { public event EventHandler&lt;RemoveItemEventArgs&gt; RemovingItem; protected virtual void OnRemovingItem(RemoveItemEventArgs args) { EventHandler&lt;RemoveItemEventArgs&gt; temp = RemovingItem; if (temp != null) { temp(this, args); } } protected override void RemoveItem(int index) { OnRemovingItem(new RemoveItemEventArgs(this[index])); base.RemoveItem(index); } public MyBindingList(IList&lt;T&gt; list) : base(list) { } public MyBindingList() { } } </code></pre> <p>I create an instance of this extended class and then I try to edit it by using <code>PropertyGrid</code>. When I delete an item, it does not fire the delete event. But when I edit the instance using method <code>RemoveAt(...)</code> it works well.</p> <ol> <li>What the source of the issue?</li> <li>Which method does <code>PropertyGrid</code> use to delete an item?</li> <li>How do I catch the deleted event when <code>PropertyGrid</code> deletes an item?</li> </ol> <p>Example :</p> <pre><code>public class Answer { public string Name { get; set; } public int Score { get; set; } } public class TestCollection { public MyBindingList&lt;Answer&gt; Collection { get; set; } public TestCollection() { Collection = new MyBindingList&lt;Answer&gt;(); } } public partial class Form1 : Form { private TestCollection _list; public Form1() { InitializeComponent(); } void ItemRemoved(object sender, RemoveItemEventArgs e) { MessageBox.Show(e.RemovedItem.ToString()); } void ListChanged(object sender, ListChangedEventArgs e) { MessageBox.Show(e.ListChangedType.ToString()); } private void Form1_Load(object sender, EventArgs e) { _list = new TestCollection(); _list.Collection.RemovingItem += ItemRemoved; _list.Collection.ListChanged += ListChanged; Answer q = new Answer {Name = "Yes", Score = 1}; _list.Collection.Add(q); q = new Answer { Name = "No", Score = 0 }; _list.Collection.Add(q); propertyGrid.SelectedObject = _list; } } </code></pre> <p>Why I have message of new item but I do not have message about deleted item when I edit the collection by PropertyGrid ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload