private void DataGridCollectionViewSource_NewItemCommitted(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);

            if (NewObjectCommitted != null)
            {
                NewObjectCommitted(this, args);
            }
        }
Exemplo n.º 2
0
        private void DataGridCollectionViewSource_EditCanceled(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);

            if (EditCanceled != null)
            {
                EditCanceled(this, args);
            }
            _SetSelectionStatus();
        }
Exemplo n.º 3
0
        private void DataGridCollectionViewSource_NewItemCanceled(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            IsEditingInProgress = false;
            DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);

            if (NewObjectCanceled != null)
            {
                NewObjectCanceled(this, args);
            }
            _SetSelectionStatus();
        }
Exemplo n.º 4
0
        private void DataGridCollectionViewSource_NewItemCanceled(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);

            if (NewObjectCanceled != null)
            {
                NewObjectCanceled(this, args);
            }

            _geocodablePage.OnNewItemCancelling();
            _SetSelectionStatus();
        }
Exemplo n.º 5
0
        private void DataGridCollectionViewSource_NewItemCommitted(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);

            if (NewObjectCommitted != null)
            {
                NewObjectCommitted(this, args);
            }

            // remove handler to property changed event when new item is commited
            _UnsubscribeFromMobileDevicePropertyChanged((MobileDevice)e.Item);
        }
Exemplo n.º 6
0
        private void DataGridCollectionViewSource_EditCanceled(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);

            if (EditCanceled != null)
            {
                EditCanceled(this, args);
            }

            // remove handler to property changed event when editing is cancelled
            _UnsubscribeFromMobileDevicePropertyChanged((MobileDevice)e.Item);
            _SetSelectionStatus();
        }
        private void DataGridCollectionViewSource_NewItemCreated(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            // Invoking changing of the item's name. Those method must be invoked, otherwise
            // grid will not understand that item in insertion ro was changed and grid wouldnt allow
            // to commit this item.
            Dispatcher.BeginInvoke(new Action <Xceed.Wpf.DataGrid.DataGridItemEventArgs>(_ChangeName),
                                   DispatcherPriority.DataBind, e);

            DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);

            if (NewObjectCreated != null)
            {
                NewObjectCreated(this, args);
            }
        }
Exemplo n.º 8
0
        private void DataGridCollectionViewSource_NewItemCreated(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            // Invoking changing of the item's name. Those method must be invoked, otherwise
            // grid will not understand that item in insertion ro was changed and grid wouldnt allow
            // to commit this item.
            Dispatcher.BeginInvoke(new ParamsDelegate(_ChangeName),
                                   System.Windows.Threading.DispatcherPriority.Render, e, _insertionRow);

            IsEditingInProgress = true;
            DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);

            if (NewObjectCreated != null)
            {
                NewObjectCreated(this, args);
            }
        }
Exemplo n.º 9
0
        private void DataGridCollectionViewSource_NewItemCreated(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            // Invoking changing of the item's name. Those method must be invoked, otherwise
            // grid will not understand that item in insertion ro was changed and grid wouldnt allow
            // to commit this item.
            Dispatcher.BeginInvoke(new ParamsDelegate(_ChangeName),
                                   System.Windows.Threading.DispatcherPriority.Render, e);

            DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);

            if (NewObjectCreated != null)
            {
                NewObjectCreated(this, args);
            }

            // when user creates new item add handler to property changed event for show validation
            _SubscribeToMobileDevicePropertyChanged((MobileDevice)e.Item);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Change item's name.
        /// </summary>
        /// <param name="e">DataGridItemEventArgs.</param>
        private void _ChangeName(Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            // Check that item's name is null.
            if (!string.IsNullOrEmpty((e.Item as Driver).Name))
            {
                return;
            }

            // Get new item's name.
            (e.Item as Driver).Name = DataObjectNamesConstructor.GetNameForNewDataObject(
                App.Current.Project.Drivers, e.Item as Driver, true);

            // Find TextBox inside the cell and select new name.
            Cell    currentCell = _InsertionRow.Cells[XceedGrid.CurrentContext.CurrentColumn];
            TextBox textBox     = XceedVisualTreeHelper.FindTextBoxInsideElement(currentCell);

            if (textBox != null)
            {
                textBox.SelectAll();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Change item's name.
        /// </summary>
        /// <param name="e">DataGridItemEventArgs.</param>
        private void _ChangeName(Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
        {
            // Check that item's name is null.
            if (!string.IsNullOrEmpty((e.Item as Order).Name))
            {
                return;
            }

            (e.Item as Order).Name = DataObjectNamesConstructor.GetNameForNewDataObject(
                (IDataObjectCollection <Order>)_collectionSource.Source, e.Item as Order, false);

            Cell currentCell = _ordersInsertionRow.Cells[OrdersGrid.CurrentContext.CurrentColumn];

            // Find TextBox inside the cell and select new name.
            TextBox textBox = XceedVisualTreeHelper.FindTextBoxInsideElement(currentCell);

            if (textBox != null)
            {
                textBox.SelectAll();
            }
        }
    public virtual void CommitEdit()
    {
      if( m_currentEditItem == null )
        return;

      DataGridItemCancelEventArgs itemCancelEventArgs = new DataGridItemCancelEventArgs( this, m_currentEditItem, false );
      m_rootDataGridCollectionViewBase.OnCommittingEdit( itemCancelEventArgs );

      if( itemCancelEventArgs.Cancel )
        throw new DataGridException( "CommitEdit was canceled." );

      if( itemCancelEventArgs.Handled != this.ItemEditionIsManuallyHandled )
        throw new InvalidOperationException( "When manually handling the item-edition process the BeginningEdit, CommittingEdit, and CancelingEdit events must all be handled." );

      if( !itemCancelEventArgs.Handled )
      {
        bool endEditCalled;
        this.EndEditInternal( m_currentEditItem, out endEditCalled );
        m_oldValuesBeforeEdition = null;
      }

      DataGridItemEventArgs itemEventArgs = new DataGridItemEventArgs( this, m_currentEditItem );
      int index = this.IndexOfSourceItem( m_currentEditItem );
      Debug.Assert( index != -1 );

      object[] items = new object[] { m_currentEditItem };
      m_currentEditItem = null;

      // Only execute or queue a replace operation if the item is not already queued for a remove operation.
      if( !this.DeferredOperationManager.ContainsItemForRemoveOperation( items[ 0 ] ) )
      {
        this.ExecuteOrQueueSourceItemOperation( new DeferredOperation(
          DeferredOperation.DeferredOperationAction.Replace,
          -1, index, items, index, items ) );
      }

      m_rootDataGridCollectionViewBase.OnEditCommitted( itemEventArgs );
    }
Exemplo n.º 13
0
 /// <summary>
 /// Change item's name.
 /// </summary>
 /// <param name="e">DataGridItemEventArgs.</param>
 protected abstract void _ChangeName(Xceed.Wpf.DataGrid.DataGridItemEventArgs e,
                                     InsertionRow insertionRow);
Exemplo n.º 14
0
 private void DataGridCollectionViewSource_EditBegun(object sender, DataGridItemEventArgs e)
 {
     DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);
     if (EditBegun != null)
         EditBegun(this, args);
 }
 /// <summary>
 /// React on cancel edit item.
 /// </summary>
 public void CancelEditItem(DataGridItemEventArgs e)
 {
     _geocodablePage.OnEditCanceled(e);
     _statusBuilder.FillSelectionStatus(e.CollectionView.Count,
         (string)App.Current.FindResource("Order"), _parentPage.OrdersView.OrdersGrid.SelectedItems.Count, _parentPage);
 }
 /// <summary>
 /// React on edit canceled.
 /// </summary>
 /// <param name="sender">Ignored.</param>
 /// <param name="e">Event args.</param>
 private void _EditCanceled(object sender, DataGridItemEventArgs e)
 {
     _geocodablePage.OnEditCanceled(e);
 }
        /// <summary>
        /// Handler raises event about editing was started.
        /// </summary>
        /// <param name="sender">Data grid control sender.</param>
        /// <param name="e">Item event args.</param>
        private void _DataGridCollectionViewSourceEditBegun(object sender, DataGridItemEventArgs e)
        {
            ESRI.ArcLogistics.Data.DataObject dataObject = e.Item as ESRI.ArcLogistics.Data.DataObject;

            if (dataObject != null)
            {
                // Raise event about item editing was started.
                _OnEditBegun(dataObject);
            }
        }
    internal override void OnEditCanceled( DataGridItemEventArgs e )
    {
      object item = e.Item;

      DataGridPageManagerBase pageManager = this.RootGroup.GetVirtualPageManager();

      // Compare cached values with current values.  If they are the same, we can clear the old values which in turn will
      // make the item non dirty.
      bool clearIsDirty = true;

      VirtualizedItemValueCollection cachedValues = pageManager.GetCachedValuesForItem( item );

      Debug.Assert( cachedValues != null );

      DataGridItemPropertyCollection itemProperties = this.ItemProperties;
      foreach( DataGridItemPropertyBase itemProperty in itemProperties )
      {
        object currentValue = itemProperty.GetValue( item );

        if( !( object.Equals( currentValue, cachedValues[ itemProperty.Name ] ) ) )
        {
          clearIsDirty = false;
          break;
        }
      }

      if( clearIsDirty )
        pageManager.ClearCachedValuesForItem( item );

      base.OnEditCanceled( e );
    }
    internal override void OnEditBegun( DataGridItemEventArgs e )
    {
      object item = e.Item;

      DataGridPageManagerBase pageManager = this.RootGroup.GetVirtualPageManager();

      if( !pageManager.IsItemDirty( item ) )
      {
        // First time we enter edit on this item.
        DataGridItemPropertyCollection itemProperties = this.ItemProperties;
        int count = itemProperties.Count;

        string[] propertyNames = new string[ count ];
        object[] cachedValues = new object[ count ];

        for( int i = 0; i < count; i++ )
        {
          DataGridItemPropertyBase itemProperty = itemProperties[ i ];
          propertyNames[ i ] = itemProperty.Name;
          cachedValues[ i ] = itemProperty.GetValue( item );
        }

        // Cache the values of the never edited before row.  This will help the developer find the corresponding row
        // in the source when times comes to commit the changes to the data source.
        pageManager.SetCachedValuesForItem( item, propertyNames, cachedValues );
      }

      base.OnEditBegun( e );
    }
 internal void OnNewItemCanceled( DataGridItemEventArgs e )
 {
   if( this.NewItemCanceled != null )
     this.NewItemCanceled( this, e );
 }
 internal void OnEditBegun( DataGridItemEventArgs e )
 {
   if( this.EditBegun != null )
     this.EditBegun( this, e );
 }
 /// <summary>
 /// Handler raises event about editing was cancelled.
 /// </summary>
 /// <param name="sender">Data grid control sender.</param>
 /// <param name="e">Item event args.</param>
 private void _DataGridCollectionViewSourceEditCanceled(object sender, DataGridItemEventArgs e)
 {
     // Raise event about item editing was cancelled.
     _OnEditCanceled((ESRI.ArcLogistics.Data.DataObject)e.Item);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Handler for the Xceed.Wpf.DataGrid.DataGridCollectionViewSource.NewItemCommitted event.
 /// </summary>
 /// <param name="sender">DataGridCollectionViewSource object.</param>
 /// <param name="e">Event arguments.</param>
 private void _DataGridCollectionViewSourceNewItemCommitted(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
 {
     // When new item is commited we should revalidate the whole collection
     // to check that items have unique names.
     _RevalidateCustomOrderPropertiesCollection();
 }
        /// <summary>
        /// Handler raise event about Editing was commited.
        /// </summary>
        /// <param name="sender">Data grid control sender.</param>
        /// <param name="e">Item event args.</param>
        private void _DataGridCollectionViewSourceEditCommitted(object sender, DataGridItemEventArgs e)
        {
            _handler.CommitedEdit(e);

            // Raise event about item editing was commited.
            _OnEditCommited((ESRI.ArcLogistics.Data.DataObject)e.Item);
        }
        /// <summary>
        /// React on edit committed.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Event args.</param>
        private void _EditCommitted(object sender, DataGridItemEventArgs e)
        {
            // If last item was edited - add new item.
            if (_locations.IndexOf((Location)e.Item) == _locations.Count - 1)
            {
                Location location = _CreateLocationWithFakeNameAndWithoutValidation();
                _locations.Add(location);

                // Make postponed bring item into view.
                Dispatcher.BeginInvoke(
                    new Action(delegate()
                    {
                        DataGridControl.BringItemIntoView(_locations[_locations.Count - 1]);

                        _ProcessLocateState();
                    }
                    ),
                    DispatcherPriority.Background);
            }
        }
 internal void OnInitializingNewItem( DataGridItemEventArgs e )
 {
   if( this.InitializingNewItem != null )
     this.InitializingNewItem( this, e );
 }
 /// <summary>
 /// React on new item committed.
 /// </summary>
 public void CommittedNewItem(DataGridItemEventArgs e)
 {
     _geocodablePage.OnNewItemCommitted();
 }
    internal void OnInitializingNewItem( DataGridItemEventArgs e )
    {
      if( this.InitializingNewItem != null )
        this.InitializingNewItem( this, e );

      if( m_parentCollectionViewSourceBase != null )
        m_parentCollectionViewSourceBase.OnInitializingNewItem( e );
    }
 /// <summary>
 /// React on EditCommited.
 /// </summary>
 public void CommitedEdit(DataGridItemEventArgs e)
 {
 }
    public virtual object AddNew()
    {
      if( !this.CanAddNew )
        throw new InvalidOperationException( "An attempt was made to add an item to a source that does not support addition." );

      // If a current AddNew has not been committed, commit it.
      this.CommitNew();
      this.CommitEdit();

      this.QueueOperationForAddNew = true;

      try
      {
        DataGridCreatingNewItemEventArgs creatingNewItemEventArgs = new DataGridCreatingNewItemEventArgs( this, null, false );

        this.RootDataGridCollectionViewBase.OnCreatingNewItem( creatingNewItemEventArgs );

        this.SetCurrentAddNew( creatingNewItemEventArgs.NewItem, -1 );

        if( creatingNewItemEventArgs.Cancel )
          throw new DataGridException( "AddNew was canceled." );

        this.CreatingNewItemIsManuallyHandled = creatingNewItemEventArgs.Handled;

        if( this.CreatingNewItemIsManuallyHandled )
        {
          if( m_currentAddItem == null )
            throw new InvalidOperationException( "An attempt was made to handle the CreatingNewItem event without providing a new item." );
        }
        else
        {
          if( !this.HasSource )
            throw new InvalidOperationException( "The CreatingNewItem event must be handled when not using an underlying data source." );

          int newItemIndex;
          object newItem = ItemsSourceHelper.AddNewDataItem( this.Enumeration, null, out newItemIndex );

          this.SetCurrentAddNew(
            newItem,
            newItemIndex );
        }

        DataGridItemEventArgs initializingNewItemEventArgs = new DataGridItemEventArgs( this, m_currentAddItem );
        this.RootDataGridCollectionViewBase.OnInitializingNewItem( initializingNewItemEventArgs );
      }
      catch
      {
        // QueueOperationForAddNew must be off when calling CancelNew
        this.QueueOperationForAddNew = false;

        if( m_currentAddItem != null )
          this.CancelNew();

        throw;
      }
      finally
      {
        this.QueueOperationForAddNew = false;
      }

      DataGridItemEventArgs itemCreatedEventArgs = new DataGridItemEventArgs( this, m_currentAddItem );
      m_rootDataGridCollectionViewBase.OnNewItemCreated( itemCreatedEventArgs );

      return m_currentAddItem;
    }
Exemplo n.º 31
0
        /// <summary>
        /// Handler raises event about new item was created and invoking changing name of zone.
        /// </summary>
        /// <param name="sender">Data grid control sender.</param>
        /// <param name="e">Item event args.</param>
        private void _DataGridCollectionViewSourceNewItemCreated(object sender,
                                                                 DataGridItemEventArgs e)
        {
            // Invoking changing of the item's name. Those method must be invoked, otherwise
            // grid will not understand that item in insertion ro was changed and grid wouldnt allow
            // to commit this item.
            Dispatcher.BeginInvoke(new ParamsDelegate(_ChangeName),
                System.Windows.Threading.DispatcherPriority.DataBind, e);

            DataObjectEventArgs args = new DataObjectEventArgs((ESRI.ArcLogistics.Data.DataObject)e.Item);
            if (NewObjectCreated != null)
                NewObjectCreated(this, args);
        }
    public virtual void CancelNew()
    {
      if( m_currentAddItem == null )
        return;

      object currentAddItem = m_currentAddItem;
      this.QueueOperationForAddNew = true;

      try
      {
        DataGridItemHandledEventArgs cancelingNewItemEventArgs = new DataGridItemHandledEventArgs( this, currentAddItem );
        this.RootDataGridCollectionViewBase.OnCancelingNewItem( cancelingNewItemEventArgs );

        if( this.CreatingNewItemIsManuallyHandled != cancelingNewItemEventArgs.Handled )
          throw new InvalidOperationException( "When manually handling the item-insertion process the CreatingNewItem, CommittingNewItem, and CancelingNewItem events must all be handled." );

        if( !cancelingNewItemEventArgs.Handled )
        {
          if( !this.HasSource )
            throw new InvalidOperationException( "The CancelingNewItem event must be handled when not using an underlying data source." );

          ItemsSourceHelper.CancelNewDataItem(
            this.Enumeration,
            null,
            m_currentAddItem,
            m_currentAddItemPosition );
        }

        this.SetCurrentAddNew( null, -1 );
      }
      finally
      {
        this.QueueOperationForAddNew = false;
      }

      if( m_deferredAddNewOperationManager != null )
      {
        m_deferredAddNewOperationManager.PurgeAddWithRemoveOrReplace();

        DeferredOperationManager deferredOperationManager = this.DeferredOperationManager;

        lock( deferredOperationManager )
        {
          if( this.ShouldDeferOperation )
          {
            deferredOperationManager.Combine( m_deferredAddNewOperationManager );
          }
          else
          {
            m_deferredAddNewOperationManager.Process();
          }
        }

        m_deferredAddNewOperationManager = null;
      }

      DataGridItemEventArgs itemEventArgs = new DataGridItemEventArgs( this, currentAddItem );
      m_rootDataGridCollectionViewBase.OnNewItemCanceled( itemEventArgs );
    }
        /// <summary>
        /// Raises event about new item was commited.
        /// </summary>
        /// <param name="sender">Data grid control sender.</param>
        /// <param name="e">Item event args.</param>
        private void _DataGridCollectionViewSourceNewItemCommitted(object sender, DataGridItemEventArgs e)
        {
            // Raise event about new item was commited.
            _handler.CommittedNewItem(e);

            if (_routesInsertionRow.Cells[HARD_ZONES_PROPERTY_NAME] != null)
                _routesInsertionRow.Cells[HARD_ZONES_PROPERTY_NAME].Visibility = Visibility.Collapsed;

            // Raise event about new item was commited.
            _OnNewObjectCommited((ESRI.ArcLogistics.Data.DataObject)e.Item);
        }
 internal void OnEditCommitted( DataGridItemEventArgs e )
 {
   if( this.EditCommitted != null )
     this.EditCommitted( this, e );
 }
    internal virtual void OnEditCommitted( DataGridItemEventArgs e )
    {
      if( this.EditCommitted != null )
        this.EditCommitted( this, e );

      if( m_parentCollectionViewSourceBase != null )
        m_parentCollectionViewSourceBase.OnEditCommitted( e );
    }
 /// <summary>
 /// Raises event about new item was cancelled.
 /// </summary>
 /// <param name="sender">Data grid control sender.</param>
 /// <param name="e">Item event args.</param>
 private void _NewItemCanceled(object sender, DataGridItemEventArgs e)
 {
     // Raise event about new item was cancelled.
     _OnNewObjectCanceled((ESRI.ArcLogistics.Data.DataObject)e.Item);
 }
    internal void OnNewItemCanceled( DataGridItemEventArgs e )
    {
      if( this.NewItemCanceled != null )
        this.NewItemCanceled( this, e );

      if( m_parentCollectionViewSourceBase != null )
        m_parentCollectionViewSourceBase.OnNewItemCanceled( e );
    }
        /// <summary>
        /// Starting editing of new item.
        /// </summary>
        /// <param name="sender">Ignore.</param>
        /// <param name="e">DataGridItemEventArgs.</param>
        private void _CollectionViewSourceCreatingNewItem(object sender, DataGridItemEventArgs e)
        {
            // Stop timer and unsubscribe from mouse move events.
            _StopTimer();

            // Turn off geocoding validation.
            if (e.Item is IGeocodable)
                (e.Item as IGeocodable).IsAddressValidationEnabled = false;

            // Close popup.
            _DeactivatePopup(true);

            // Remember edited item and subscribe to it's property changed event.
            _InvalidItem = e.Item as IDataErrorInfo;
            (e.Item as INotifyPropertyChanged).PropertyChanged += new PropertyChangedEventHandler
                (_EditedItemPropertyChanged);

            // If new item already has errors - show callout.
            _dataGrid.Dispatcher.BeginInvoke(new Action(delegate()
            {
                var column = _GetColumnWithError(_InvalidItem);
                if (column != null)
                    _InitCallout(column);
            }), DispatcherPriority.ApplicationIdle);
        }
    public virtual void CommitNew()
    {
      if( m_currentAddItem == null )
        return;

      object item = m_currentAddItem;
      DeferredOperation addOperationToNotifyIfNotAlreadyQueued = null;
      this.QueueOperationForAddNew = true;

      try
      {
        DataGridCommittingNewItemEventArgs committingNewItemEventArgs =
          new DataGridCommittingNewItemEventArgs( this, m_currentAddItem, false );

        this.RootDataGridCollectionViewBase.OnCommittingNewItem( committingNewItemEventArgs );

        if( committingNewItemEventArgs.Cancel )
          throw new DataGridException( "CommitNew was canceled." );

        if( this.CreatingNewItemIsManuallyHandled != committingNewItemEventArgs.Handled )
          throw new InvalidOperationException( "When manually handling the item-insertion process the CreatingNewItem, CommittingNewItem, and CancelingNewItem events must all be handled." );

        if( !committingNewItemEventArgs.Handled )
        {
          if( !this.HasSource )
            throw new InvalidOperationException( "The CommittingNewItem event must be handled when not using an underlying data source." );

          int addItemPosition = m_currentAddItemPosition;
          ItemsSourceHelper.EndNewDataItem( this.Enumeration, null, m_currentAddItem, ref addItemPosition );

          addOperationToNotifyIfNotAlreadyQueued = new DeferredOperation(
            DeferredOperation.DeferredOperationAction.Add,
            addItemPosition + 1, addItemPosition,
            new object[] { m_currentAddItem } );
        }
        else
        {
          if( committingNewItemEventArgs.Index == -1 )
            throw new InvalidOperationException( "An attempt was made to handle the CommittingNewItem event without providing the index at which the new item was inserted." );

          if( committingNewItemEventArgs.NewCount == -1 )
            throw new InvalidOperationException( "An attempt was made to handle the CommittingNewItem event without providing the new item count." );

          if( committingNewItemEventArgs.Index >= committingNewItemEventArgs.NewCount )
            throw new InvalidOperationException( "The index at which the new item was inserted was greater than the new item count." );

          addOperationToNotifyIfNotAlreadyQueued = new DeferredOperation(
            DeferredOperation.DeferredOperationAction.Add,
            committingNewItemEventArgs.NewCount, committingNewItemEventArgs.Index,
            new object[] { m_currentAddItem } );
        }

        this.SetCurrentAddNew( null, -1 );
      }
      finally
      {
        this.QueueOperationForAddNew = false;
      }

      if( m_deferredAddNewOperationManager != null )
      {
        m_deferredAddNewOperationManager.PurgeAddWithRemoveOrReplace();

        DeferredOperationManager deferredOperationManager = this.DeferredOperationManager;

        lock( deferredOperationManager )
        {
          if( this.ShouldDeferOperation )
          {
            deferredOperationManager.Combine( m_deferredAddNewOperationManager );
          }
          else
          {
            m_deferredAddNewOperationManager.Process();
          }
        }

        m_deferredAddNewOperationManager = null;
      }
      else
      {
        Debug.Assert( !this.IsSourceSupportingChangeNotification );

        // No pending operation was in m_deferredAddNewOperationManager,
        // so the list have not trigger notification for the new item added.
        // We will, in that case, raise the notification ourself.
        this.ExecuteOrQueueSourceItemOperation( addOperationToNotifyIfNotAlreadyQueued );
      }

      DataGridItemEventArgs itemEventArgs = new DataGridItemEventArgs( this, item );
      m_rootDataGridCollectionViewBase.OnNewItemCommitted( itemEventArgs );
    }
        /// <summary>
        /// Editing in grid finished, need check for validation.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _CollectionViewSourceFinishEdit(object sender, DataGridItemEventArgs e)
        {
            // Unsubscribe from events.
            _UnsubscribeFromEditingEvents(e.Item);

            // If there are no cell with error on edited item - do validation for whole collection.
            if (_GetInvalidColumns(e.Item as IDataErrorInfo).Count == 0)
                _Validate();

            // Start timer and subscribe to item's, cells events.
            _StartTimerSubscribeToEvent();
        }
    public virtual void EditItem( object item )
    {
      if( item == null )
        throw new ArgumentNullException( "item" );

      this.CommitNew();

      if( m_currentEditItem == item )
        return;

      this.CommitEdit();

      DataGridItemCancelEventArgs itemCancelEventArgs = new DataGridItemCancelEventArgs( this, item, false );
      m_rootDataGridCollectionViewBase.OnBeginningEdit( itemCancelEventArgs );

      if( itemCancelEventArgs.Cancel )
        throw new DataGridException( "EditItem was canceled." );

      this.ItemEditionIsManuallyHandled = itemCancelEventArgs.Handled;

      if( !this.ItemEditionIsManuallyHandled )
      {
        bool beginEditCalled;
        this.EditItemInternal( item, out beginEditCalled );

        if( !beginEditCalled )
        {
          DataGridItemPropertyCollection itemProperties = this.ItemProperties;
          int count = itemProperties.Count;
          m_oldValuesBeforeEdition = new object[ count ];

          for( int i = 0; i < count; i++ )
          {
            m_oldValuesBeforeEdition[ i ] = itemProperties[ i ].GetValue( item );
          }
        }
      }

      m_currentEditItem = item;
      DataGridItemEventArgs itemEventArgs = new DataGridItemEventArgs( this, item );
      m_rootDataGridCollectionViewBase.OnEditBegun( itemEventArgs );
    }
        /// <summary>
        /// Editing new item in grid finished, need check for validation.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Ignored.</param>
        private void _CollectionViewSourceNewItemFinishEdit(object sender, DataGridItemEventArgs e)
        {
            // Close callout.
            _ClosePopup(false);

            // Enable geocoding validation.
            if (e.Item is IGeocodable)
                (e.Item as IGeocodable).IsAddressValidationEnabled = true;

            // Unsubscribe from events.
            _UnsubscribeFromEditingEvents(e.Item);

            // We need to do invoking, to wait while new item will be comitted to the view.
            _dataGrid.Dispatcher.BeginInvoke(new Action(delegate()
            {
                _Validate();
            }), DispatcherPriority.ApplicationIdle);
        }
    public virtual void CancelEdit()
    {
      if( !this.CanCancelEdit )
        throw new InvalidOperationException( "An attempt was made to cancel the edit process on a source that does not support cancellation." );

      if( m_currentEditItem == null )
        return;

      DataGridItemHandledEventArgs itemHandleEventArgs = new DataGridItemHandledEventArgs( this, m_currentEditItem );
      m_rootDataGridCollectionViewBase.OnCancelingEdit( itemHandleEventArgs );

      if( itemHandleEventArgs.Handled != this.ItemEditionIsManuallyHandled )
        throw new InvalidOperationException( "An attempt was made to manually handle the edit prcess without handling the BeginningEdit, CommittingEdit, and CancelingEdit events." );

      if( !itemHandleEventArgs.Handled )
      {
        bool cancelEditCalled;
        this.CancelEditInternal( m_currentEditItem, out cancelEditCalled );

        DataGridItemPropertyCollection itemProperties = this.ItemProperties;
        int count = itemProperties.Count;

        if( ( !cancelEditCalled ) && ( count > 0 ) )
        {
          itemProperties.SuspendUnboundItemPropertyChanged( m_currentEditItem );

          try
          {
            for( int i = 0; i < count; i++ )
            {
              DataGridItemPropertyBase itemProperty = itemProperties[ i ];

              bool readOnly = ( ( m_currentEditItem == m_currentAddItem )
                              && itemProperty.OverrideReadOnlyForInsertion.HasValue
                              && itemProperty.OverrideReadOnlyForInsertion.Value )
                ? false
                : itemProperty.IsReadOnly;

              if( !readOnly )
              {
                try
                {
                  itemProperty.SetValue( m_currentEditItem, m_oldValuesBeforeEdition[ i ] );
                }
                catch
                {
                  // Swallow any Exception, setting a property to is old value should not throw.
                }
              }
            }
          }
          finally
          {
            itemProperties.ResumeUnboundItemPropertyChanged( m_currentEditItem );
          }
        }
      }

      DataGridItemEventArgs itemEventArgs = new DataGridItemEventArgs( this, m_currentEditItem );
      m_currentEditItem = null;
      m_rootDataGridCollectionViewBase.OnEditCanceled( itemEventArgs );
    }
Exemplo n.º 44
0
 /// <summary>
 /// Handler for the Xceed.Wpf.DataGrid.DataGridCollectionViewSource.EditCommitted event.
 /// </summary>
 /// <param name="sender">DataGridCollectionViewSource object.</param>
 /// <param name="e">Event arguments.</param>
 private void _DataGridCollectionViewSourceEditCommitted(object sender, Xceed.Wpf.DataGrid.DataGridItemEventArgs e)
 {
     _RevalidateCustomOrderPropertiesCollection();
 }