コード例 #1
0
        private void GPSes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int newIndex = e.NewStartingIndex;
                GPSes.Add(GPSCollection[newIndex]);
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                List <GPS> tempListOfRemovedItems = e.OldItems.OfType <GPS>().ToList();
                GPSes.Delete(tempListOfRemovedItems[0].ID);
            }
            break;

            case NotifyCollectionChangedAction.Replace:
            {
                List <GPS> tempListOfGPS = e.NewItems.OfType <GPS>().ToList();
                GPSes.Update(tempListOfGPS[0]);              // As the IDs are unique, only one row will be effected hence first index only
            }
            break;
            }
        }
コード例 #2
0
        private void GPSCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            EditSuccess = false;
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
            {
                int newIndex = e.NewStartingIndex;
                GPS newGPS   = GPSCollection[newIndex];
                if (_addToCollectionOnly)
                {
                    CurrentEntity = newGPS;
                }
                else
                {
                    EditSuccess = GPSes.Add(newGPS);
                    if (EditSuccess)
                    {
                        CurrentEntity = newGPS;
                    }
                }
            }
            break;

            case NotifyCollectionChangedAction.Remove:
            {
                if (_gpsRemovedByEject)
                {
                    _gpsRemovedByEject = false;
                }
                else
                {
                    List <GPS> tempListOfRemovedItems = e.OldItems.OfType <GPS>().ToList();
                    EditSuccess = GPSes.Delete(tempListOfRemovedItems[0].Code);
                }
            }
            break;

            case NotifyCollectionChangedAction.Replace:
            {
                List <GPS> tempList = e.NewItems.OfType <GPS>().ToList();
                EditSuccess = GPSes.Update(tempList[0]);               // As the IDs are unique, only one row will be effected hence first index only
            }
            break;
            }
        }