using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace WinFormClient
{
    public class RemovableBindingList<T> : BindingList<T>
    {
        public event EventHandler<RemovingItemEventArgs> RemovingItem;

        protected override void RemoveItem(int index)
        {
            // load up the item to be removed to args and fire event if assigned
            RemovingItemEventArgs args = null;
            if (RemovingItem != null)
            {
                args = new RemovingItemEventArgs(false, this[index]);
                if (RemovingItem != null)
                {
                    RemovingItem(this, args);
                }
            }

            if (!args.Cancel)
                base.RemoveItem(index);
        }

        #region constructors

        public RemovableBindingList(IList<T> list)
            : base(list) { }

        public RemovableBindingList() : base() { }

        #endregion
    }
}