Get Deleted Item in ItemChanging event of BindingList

前端 未结 5 1184
生来不讨喜
生来不讨喜 2020-12-29 22:23

I am using Binding List in my application along with ItemChanged event.

Is there any way I could know the previous values of properties in ItemChanged event. Curren

5条回答
  •  一个人的身影
    2020-12-29 22:51

    An alternative approach to this problem is to wrap an ObservableCollection with a BindingList. This code works for me -

        public void X()
        {
            ObservableCollection oc = new ObservableCollection();
            BindingList bl = new BindingList(oc);
            oc.CollectionChanged += oc_CollectionChanged;
            bl.Add(new object());
            bl.RemoveAt(0);
        }
    
        void oc_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (object o in e.OldItems)
                {
                    //o was deleted
                }
            }
        }
    
        

    提交回复
    热议问题