Ticket T292053
Visible to All Users

PivotGrid Cell Edit implementation

created 9 years ago (modified 9 years ago)

Hi,

I am using the suggestion described in https://www.devexpress.com/Support/Center/Question/Details/Q324491
to implement a Cell Edit functionality within the Pivot Grid.

However, I have this requirement where the user would select multiple cells and then press "enter" (for example) to enter into the "edit mode". Once the user enters a value, I would then need to capture the EditedValue and apply it to all the selected cells.

Currently, I am stuck with entering into "Edit Mode". Of course this is a simple task when an individual cell has focus and we can trap the "KeyDown" event on the TextEdit control. However, not so easy when multiple cells are selected. I can see that KeyDown event is fired on the G rid Control.

I can do something along the lines of:

C#
if (e.Key != Key.Enter) {     return; } var grid = sender as PivotGridControl; if (grid != null && grid.Selection.IsEmpty) {     return; } var firstCell = grid.GetCellInfo(grid.Selection.Left, grid.Selection.Top);

After this point, how do I enter into Edit Mode of the selected cell please?

Thanks!
Suneth

Answers approved by DevExpress Support

created 9 years ago (modified 8 years ago)

Hello Suneth,
To implement multi-editing, you need to save selected cells and edit them in cycle. Please check the attached sample. I hope you will find it useful

Update:
We recommend downloading the actual sample project demonstrating how to implement the data editing functionality from the T410760: How to define a custom cell template that allows performing data editing example.

    Show previous comments (13)
    DevExpress Support Team 9 years ago

      Hello Suneth,
      Let me explain how my previous sample works and how the editor will be switched to the InplaceActive mode. Please look at the EditValue method:

      C#
      void EditValue(object sender) { TextEdit edit = sender as TextEdit; if (edit == null || edit.DataContext as CellsAreaItem == null) return; CellsAreaItem item = edit.DataContext as CellsAreaItem; decimal newValue; decimal oldValue; if (edit.EditValue != null && decimal.TryParse(edit.EditValue.ToString(), out newValue)) { if (item.Value == null || !decimal.TryParse(item.Value.ToString(), out oldValue) || selectedCells == null) return; foreach (System.Drawing.Point selectedCell in selectedCells) { PivotDrillDownDataSource ds = pivotGridControl1.CreateDrillDownDataSource(selectedCell.X, selectedCell.Y); decimal difference = newValue - oldValue; decimal factor = (difference == newValue) ? (difference / ds.RowCount) : (difference / oldValue); for (int i = 0; i < ds.RowCount; i++) { decimal value = Convert.ToDecimal(ds[i][fieldExtendedPrice]); ds[i][fieldExtendedPrice] = (value == 0m) ? factor : value * (1m + factor); } } pivotGridControl1.RefreshData(); edit.EditMode = EditMode.InplaceInactive; } else { } }

      As you can see, the edit variable is passes directly to the method from the TextEdit_KeyDown method. Let's see the pivotGridControl1_KeyDown method:

      C#
       if (e.Key == System.Windows.Input.Key.Enter) {     //OpenEditorCode     PivotGridControl pivotGridControl = sender as PivotGridControl;     LayoutHelper.ForEachElement(pivotGridControl, new LayoutHelper.ElementHandler(i => {         if (i is TextEdit)         {             TextEdit edit = (TextEdit)i;             if (edit == null || edit.DataContext as CellsAreaItem == null) return;             CellsAreaItem item = edit.DataContext as CellsAreaItem;             if (item.RowIndex != pivotGridControl.FocusedCell.Y || item.ColumnIndex != pivotGridControl.FocusedCell.X)                 return;             if (item.IsTotalAppearance)                 return;             selectedCells = pivotGridControl1.MultiSelection.SelectedCells;             edit.EditMode = EditMode.InplaceActive;             FocusManager.SetFocusedElement(pivotGridControl, edit);         }     })); }

      I used the LayoutHelper class. This class can help to iterate though internal ui elements. As you can see, I check their classes by using this condition:

      C#
      if (i is TextEdit)

      Then I check whether a cell is focused:

      C#
      if (item.RowIndex != pivotGridControl.FocusedCell.Y || item.ColumnIndex != pivotGridControl.FocusedCell.X)    return;

      If you have any further questions, feel free to contact me.

        Hi devexpress team,

        In the above example, the field to be edited is hardcoded 'fieldExtendedPrice',
        Please help me with a case where I have the pivot grid, and data loading is dynamic.
        Also I could edit any cell and save it to the corresponding datasource.

        DevExpress Support Team 6 years ago

          Hello,

          I've created a separate ticket on your behalf (T673413: PivotGrid Cell Edit implementation). It has been placed in our processing queue and will be answered shortly.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.