/// <summary>
 /// Raises the <see cref="CurrentItemChanging"/> event.
 /// </summary>
 /// <param name="args"></param>
 protected virtual void OnCurrentItemChanging(CurrentItemChangingEventArgs args)
 {
     if (this.currentItemChangingEvent != null)
     {
         this.currentItemChangingEvent(this, args);
     }
 }
        /// <summary>
        /// Performs the core logic of updating the current item.
        /// </summary>
        /// <param name="item">The item that needs to be set as current.</param>
        /// <param name="synchronizeOriginal">True to apply the change to the original <see cref="System.ComponentModel.ICollectionView"/> instance (if any), false otherwise.</param>
        /// <returns>True if operation was successful, false otherwise.</returns>
        protected virtual bool SetCurrentItemCore(IDataSourceItem item, bool synchronizeOriginal)
        {
            if (this[UpdatingCurrentStateKey])
            {
                return(false);
            }

            if (!this.IsNewCurrentItem(item))
            {
                return(false);
            }

            CurrentItemChangingEventArgs args = new CurrentItemChangingEventArgs(item, synchronizeOriginal);

            this.OnCurrentItemChanging(args);

            if (args.Cancel)
            {
                return(false);
            }

            this[UpdatingCurrentStateKey] = true;

            bool success = true;

            if (synchronizeOriginal &&
                this.currencyMode == CurrencyManagementMode.LocalAndExternal &&
                this.sourceCollectionAsCollectionView != null)
            {
                success = this.sourceCollectionAsCollectionView.MoveCurrentTo(item == null ? null : item.Value);
            }

            if (success)
            {
                this.currentItem = item;

                // do not raise CurrentItemChanged if we are currently refreshing the source
                if (!this[RefreshingStateKey])
                {
                    this.OnCurrentItemChanged(EventArgs.Empty);
                }
            }

            this[UpdatingCurrentStateKey] = false;

            return(success);
        }