Esempio n. 1
0
 void flex_CellEditEnded(object sender, CellEditEventArgs e)
 {
     if (!e.Cancel && _pendingAction is EditAction && _pendingAction.SaveNewState())
     {
         _flex.UndoStack.AddAction(_pendingAction);
     }
     _pendingAction = null;
 }
Esempio n. 2
0
 // customize editor by changing the appearance of the selection
 void _grid_PrepareCellForEdit(object sender, CellEditEventArgs e)
 {
     var b = e.Editor as Border;
     var tb = b.Child as TextBox;
     if (tb != null)
     {
         tb.Background = new SolidColorBrush(Colors.Black);
         tb.Foreground = new SolidColorBrush(Colors.White);
     }
 }
Esempio n. 3
0
 // undo/redo edits
 void flex_PrepareCellForEdit(object sender, CellEditEventArgs e)
 {
     _pendingAction = new EditAction(_flex);
 }
Esempio n. 4
0
 private void _grid_RowEditEnded(object sender, CellEditEventArgs e)
 {
     IEditableCollectionView editableCollectionView = _grid.EditableCollectionView;
     if (editableCollectionView != null)
     {
         if (_grid.NewRowPosition == NewRowPosition.Top && _grid.IsRangeValid(e.CellRange) && _grid.Rows[e.Row] == _nrt)
         {
             object dataItem = _nrt.DataItem;
             _nrt.DataItem = null;
             if (!e.CancelEdits && dataItem != null)
             {
                 object newItem = editableCollectionView.AddNew();
                 CopyItem(dataItem, newItem);
                 _grid.IsCommitting = true;
                 editableCollectionView.CommitNew();
                 _grid.CollectionView.Refresh();
                 _grid.IsCommitting = false;
                 if (!_grid.IsMouseDown)
                 {
                     SelectNewRowTemplate();
                 }
             }
         }
         else if (editableCollectionView.IsAddingNew && e.Row > -1 && _grid.Rows[e.Row].DataItem == editableCollectionView.CurrentAddItem)
         {
             _grid.IsCommitting = true;
             editableCollectionView.CommitNew();
             _grid.CollectionView.Refresh();
             _grid.IsCommitting = false;
         }
     }
 }
Esempio n. 5
0
 /// <summary>
 ///     Raises the <see cref="E:C1.WPF.FlexGrid.C1FlexGrid.RowEditEnding" /> event.
 /// </summary>
 /// <param name="e">
 ///     <see cref="T:C1.WPF.FlexGrid.CellEditEventArgs" /> that contains the event data.
 /// </param>
 protected internal virtual void OnRowEditEnding(CellEditEventArgs e)
 {
     if (RowEditEnding != null)
     {
         RowEditEnding(this, e);
     }
 }
Esempio n. 6
0
 private void _grid_BeginningEdit(object sender, CellEditEventArgs e)
 {
     if (!e.Cancel && _grid.Rows[e.Row] is NewRowTemplate)
     {
         IEditableCollectionView editableCollectionView = _grid.EditableCollectionView;
         if (editableCollectionView != null && editableCollectionView.CanAddNew)
         {
             if (_grid.NewRowPosition != NewRowPosition.Top)
             {
                 object addedItem = editableCollectionView.IsAddingNew ? editableCollectionView.CurrentAddItem : editableCollectionView.AddNew();
                 _grid.SelectedItem = addedItem;
                 UpdateNewRowTemplate();
             }
             else if (_nrt.DataItem == null)
             {
                 _nrt.DataItem = editableCollectionView.AddNew();
                 editableCollectionView.CancelNew();
             }
         }
     }
 }
Esempio n. 7
0
 /// <summary>
 ///     Raises the <see cref="E:C1.WPF.FlexGrid.C1FlexGrid.CellEditEnded" /> event.
 /// </summary>
 /// <param name="e">
 ///     <see cref="T:C1.WPF.FlexGrid.CellEditEventArgs" /> that contains the event data.
 /// </param>
 protected internal virtual void OnCellEditEnded(CellEditEventArgs e)
 {
     if (CellEditEnded != null)
     {
         CellEditEnded(this, e);
     }
 }
Esempio n. 8
0
 /// <summary>
 ///     Raises the <see cref="E:C1.WPF.FlexGrid.C1FlexGrid.PrepareCellForEdit" /> event.
 /// </summary>
 /// <param name="e">
 ///     <see cref="T:C1.WPF.FlexGrid.CellEditEventArgs" /> that contains the event data.
 /// </param>
 protected internal virtual void OnPrepareCellForEdit(CellEditEventArgs e)
 {
     if (PrepareCellForEdit != null)
     {
         PrepareCellForEdit(this, e);
     }
 }
Esempio n. 9
0
 /// <summary>
 ///     Parses a string into rows and columns and applies the content to a given range.
 /// </summary>
 /// <param name="text">Text to parse into the grid.</param>
 /// <param name="rng">Range where the text will be pasted.</param>
 /// <param name="copyMode">
 ///     Whether the string contains header information that should
 ///     be discarded when applying the values to the cells.
 /// </param>
 /// <remarks>
 ///     <para>
 ///         The string contains rows delimited by newline characters and cells delimited
 ///         by tabs (standard clipboard format).
 ///     </para>
 ///     <para>
 ///         Only the top left cell of the <paramref name="rng" /> parameter is used;
 ///         the number of rows and columns copied to the grid is determined by the content
 ///         of the <paramref name="text" /> parameter.
 ///     </para>
 /// </remarks>
 public void SetClipString(string text, CellRange rng, ClipboardCopyMode copyMode)
 {
     text = text.Replace("\r\n", "\r");
     if (text.Length > 0 && text[text.Length - 1] == '\r')
     {
         text = text.Substring(0, text.Length - 1);
     }
     if (ClipboardPasteMode == ClipboardCopyMode.ExcludeHeader && !rng.IsSingleCell)
     {
         text = ExpandClipString(text, rng.RowSpan, rng.ColumnSpan);
     }
     int topRow = rng.TopRow;
     int leftColumn = rng.LeftColumn;
     rng = new CellRange(topRow, leftColumn);
     string[] lines = text.Split('\r', '\n');
     int lineIndex = 0;
     int itemIndex = 0;
     switch (copyMode)
     {
         case ClipboardCopyMode.IncludeAllHeaders:
         {
             lineIndex = itemIndex = 1;
             break;
         }
         case ClipboardCopyMode.IncludeColumnHeaders:
         {
             lineIndex = 1;
             break;
         }
         case ClipboardCopyMode.IncludeRowHeaders:
         {
             itemIndex = 1;
             break;
         }
     }
     while (lineIndex < lines.Length && topRow < Rows.Count)
     {
         Row row = Rows[topRow];
         rng.Row2 = topRow;
         if (row.Visible)
         {
             string line = lines[lineIndex];
             string[] items = line.Split('\t');
             leftColumn = rng.LeftColumn;
             while (itemIndex < items.Length && leftColumn < Columns.Count)
             {
                 Column column = Columns[leftColumn];
                 rng.Column2 = Math.Max(rng.Column2, leftColumn);
                 if (!column.Visible)
                 {
                     itemIndex--;
                 }
                 else if (!IsReadOnly && !row.IsReadOnly && !column.IsReadOnly)
                 {
                     CellRange cellRange = new CellRange(topRow, leftColumn);
                     CellEditEventArgs cellEditEventArg = new CellEditEventArgs(Cells, cellRange, null, false);
                     OnBeginningEdit(cellEditEventArg);
                     if (!cellEditEventArg.Cancel)
                     {
                         object item = items[itemIndex];
                         try
                         {
                             this[topRow, leftColumn] = item;
                             UpdateAggregates(column, false);
                         }
                         catch
                         {
                         }
                         OnCellEditEnded(cellEditEventArg);
                     }
                 }
                 itemIndex++;
                 leftColumn++;
             }
         }
         else
         {
             lineIndex--;
         }
         lineIndex++;
         topRow++;
     }
     Selection = rng;
     for (int i = rng.LeftColumn; i <= rng.RightColumn; i++)
     {
         UpdateAggregates(Columns[i], false);
     }
 }
Esempio n. 10
0
 /// <summary>
 ///     Raises the <see cref="E:C1.WPF.FlexGrid.C1FlexGrid.BeginningEdit" /> event.
 /// </summary>
 /// <param name="e">
 ///     <see cref="T:C1.WPF.FlexGrid.CellEditEventArgs" /> that contains the event data.
 /// </param>
 protected internal virtual void OnBeginningEdit(CellEditEventArgs e)
 {
     if (BeginningEdit != null)
     {
         BeginningEdit(this, e);
     }
 }
Esempio n. 11
0
 public bool FinishEditing(bool cancel)
 {
     _validationErrors = null;
     bool needGroupRefresh = false;
     if (ActiveEditor == null)
     {
         return true;
     }
     if (!_grid.IsRangeValid(EditorRange))
     {
         cancel = true;
     }
     CellEditEventArgs e = new CellEditEventArgs(_grid.Cells, EditorRange, ActiveEditor, cancel);
     _grid.OnCellEditEnding(e);
     cancel = cancel | e.Cancel;
     if (cancel)
     {
         if (_grid.IsRangeValid(EditorRange))
         {
             _grid.Rows[e.Row].UpdateErrors();
             if (EditorRange.IsSingleCell)
             {
                 _grid[e.Row, e.Column] = _editCellOriginalValue;
             }
         }
     }
     else if (!EditorRange.IsSingleCell)
     {
         object val = Util.Util.GetValueFromBindings(ActiveEditor);
         foreach (CellRange cell in EditorRange.Cells)
         {
             _grid[cell.Row, cell.Column] = _grid.StringToNumber(val, cell.Column);
         }
         needGroupRefresh = NeedGroupRefresh();
     }
     else if (_grid.Columns[e.Column].Binding == null || _grid.Rows[e.Row].DataItem == null)
     {
         object val = Util.Util.GetValueFromBindings(ActiveEditor);
         _grid[e.Row, e.Column] = _grid.StringToNumber(val, e.Column);
     }
     else
     {
         Util.Util.UpdateBindingSource(ActiveEditor);
         if (_validationErrors != null)
         {
             if (Util.Util.ContainsFocus(_grid))
             {
                 ActivateEditor();
             }
             return false;
         }
         _grid.Rows[e.Row].UpdateErrors();
     }
     _editCellOriginalValue = null;
     _grid.OnCellEditEnded(e);
     if (ActiveEditor != null)
     {
         ActiveEditor.PreviewKeyDown -= _editor_PreviewKeyDown;
         ActiveEditor.KeyDown -= _editor_KeyDown;
     }
     ActiveEditor = null;
     _grid.Cells.Invalidate(EditorRange);
     EditorRange = CellRange.Empty;
     Column column = e.Column <= -1 || e.Column >= _grid.Columns.Count ? null : _grid.Columns[e.Column];
     _grid.UpdateAggregates(column, false);
     if (needGroupRefresh && _grid.CollectionView != null)
     {
         if (_grid.EditableCollectionView == null || !_grid.EditableCollectionView.IsAddingNew && !_grid.EditableCollectionView.IsEditingItem)
         {
             _grid.IsCommitting = true;
             _grid.CollectionView.Refresh();
             _grid.IsCommitting = false;
         }
     }
     return true;
 }
Esempio n. 12
0
 private bool CommitRowChanges(bool cancel)
 {
     if (!FinishEditing(cancel))
     {
         return false;
     }
     IEditableCollectionView editableCollectionView = _grid.EditableCollectionView;
     CellRange rng = new CellRange(_grid.Selection.Row, -1);
     CellEditEventArgs e = new CellEditEventArgs(_grid.Cells, rng, ActiveEditor, cancel);
     if (editableCollectionView != null && (editableCollectionView.IsEditingItem || editableCollectionView.IsAddingNew))
     {
         _grid.OnRowEditEnding(e);
         if (e.Cancel)
         {
             return false;
         }
         if (editableCollectionView.IsEditingItem)
         {
             _grid.IsCommitting = true;
             if (!cancel || !editableCollectionView.CanCancelEdit)
             {
                 editableCollectionView.CommitEdit();
             }
             else
             {
                 editableCollectionView.CancelEdit();
             }
             _grid.IsCommitting = false;
         }
         _grid.OnRowEditEnded(e);
         if (_grid.CollectionView != null && _grid.ShowErrors)
         {
             _grid.Cells.Invalidate(new CellRange(rng.Row, -1));
             _grid.RowHeaders.Invalidate(new CellRange(rng.Row, -1));
         }
     }
     return true;
 }
Esempio n. 13
0
 public bool StartEditing(bool fullEdit, int row, int col)
 {
     if (!FinishEditing(false))
     {
         return false;
     }
     CellRange rng = new CellRange(row, col);
     if (!_grid.IsRangeValid(rng))
     {
         return false;
     }
     CellRange mergedRange = _grid.GetMergedRange(_grid.Cells, rng);
     row = mergedRange.Row;
     col = mergedRange.Column;
     if (!AllowEditing(row, col))
     {
         return false;
     }
     Row r = _grid.Rows[row];
     _grid.EditCanceled = false;
     CellEditEventArgs e = new CellEditEventArgs(_grid.Cells, mergedRange, null, false);
     _grid.OnBeginningEdit(e);
     if (e.Cancel)
     {
         _grid.EditCanceled = true;
         return false;
     }
     CellRange selection = _grid.Selection;
     if (selection.Row != row || selection.Column != col)
     {
         _grid.Select(row, col, false);
     }
     _grid.ScrollIntoView(row, col);
     if (!AllowEditing(row, col))
     {
         return false;
     }
     if (r != _grid.Rows[row])
     {
         if (_grid.Rows[row].DataItem != _grid.EditableCollectionView.CurrentAddItem)
         {
             return false;
         }
     }
     object dataItem = _grid.Rows[row].DataItem;
     if (dataItem != null && mergedRange.IsSingleCell)
     {
         if (_grid.EditableCollectionView != null && _grid.EditableCollectionView.CurrentEditItem != dataItem)
         {
             _grid.EditableCollectionView.EditItem(dataItem);
             if (!AllowEditing(row, col))
             {
                 return false;
             }
         }
     }
     ICellFactory cellFactory = _grid.GetCellFactory();
     ActiveEditor = cellFactory.CreateCellEditor(_grid, CellType.Cell, mergedRange);
     if (_grid.AutoComplete)
     {
         C1FlexComboBox comboBox = Util.Util.GetFirstChildOfType<C1FlexComboBox>(ActiveEditor);
         if (comboBox != null && !comboBox.HasItems())
         {
             AddAutoCompleteItems(row, col, comboBox);
         }
     }
     if (ActiveEditor != null)
     {
         e = new CellEditEventArgs(_grid.Cells, mergedRange, ActiveEditor, false);
         _grid.OnPrepareCellForEdit(e);
         EditorRange = mergedRange;
         _fullEdit = fullEdit;
         _grid.Cells.ActivateEditor(ActiveEditor, EditorRange);
         ActiveEditor.PreviewKeyDown += _editor_PreviewKeyDown;
         ActiveEditor.KeyDown += _editor_KeyDown;
         ActivateEditor();
     }
     _editCellOriginalValue = _grid[row, col];
     return ActiveEditor != null;
 }
Esempio n. 14
0
        // values can be edited, formulas cannot
        void _grid_BeginningEdit(object sender, CellEditEventArgs e)
        {
            // get the row/column being edited
            var row = _grid.Rows[e.CellRange.Row];
            var field = row.DataItem as FormField;

            if (row is GroupRow || !string.IsNullOrEmpty(field.Formula))
            {
                e.Cancel = true;
            }
        }
Esempio n. 15
0
 // cancel standard editing for our custom cells (they are editors already)
 void flex_BeginningEdit(object sender, CellEditEventArgs e)
 {
     var t = GetCellType(e.CellRange);
     if (t != null)
     {
         e.Cancel = true;
     }
 }