Recent

Author Topic: TsCustomWorksheetGrid: vk_Back and vk_Delete has not same effect.  (Read 3119 times)

Soner

  • Sr. Member
  • ****
  • Posts: 305
When you delete a cell with vk_back then the spreadsheet will be calculated deleting with vk_delete does not "fire up recalculate event".
Is this bug or feature?

Write in the cells a1..a5 nummer values and a6 the formula "=sum(a1:a5)".
Now when you delete  one of the cells a1..a5 with vk_back key then the cell  a6 will be updated. But when you delete it wih vk_delete then a6 has still old value. ( press for deleting: vk_back + vk_enter or vk_delete + vk_enter).

Very strange is that in fpspreadsheetgrid.pas there is no key handler for vk_back key. It is handled only in base class TCustomDrawGrid.
For additional info  look at my comments.
Quote
procedure TsCustomWorksheetGrid.KeyDown(var Key : Word; Shift : TShiftState);
//..
  case Key of
    //..
    VK_DELETE: // when you add here VK_BACK then spreedsheat will be also not recalculated
      if (ssCtrl in Shift) then
        Worksheet.DeleteSelection
      else
        Worksheet.EraseSelection(true);
      // Maybe Recalculate ore something similar for vk_delete must be called.
  end;
end;


wp

  • Hero Member
  • *****
  • Posts: 11854
Re: TsCustomWorksheetGrid: vk_Back and vk_Delete has not same effect.
« Reply #1 on: August 27, 2018, 11:20:07 pm »
When you delete a cell with vk_back then the spreadsheet will be calculated deleting with vk_delete does not "fire up recalculate event".
Is this bug or feature?
Bug. Fixed in ccr-r6615.

Very strange is that in fpspreadsheetgrid.pas there is no key handler for vk_back key. It is handled only in base class TCustomDrawGrid.
For additional info  look at my comments.
Quote
procedure TsCustomWorksheetGrid.KeyDown(var Key : Word; Shift : TShiftState);
//..
  case Key of
    //..
    VK_DELETE: // when you add here VK_BACK then spreedsheat will be also not recalculated
      if (ssCtrl in Shift) then
        Worksheet.DeleteSelection
      else
        Worksheet.EraseSelection(true);
      // Maybe Recalculate ore something similar for vk_delete must be called.
  end;
end;
VK_BACK is handled by the cell editor which communicates with the grid - this is like with all Lazarus grids. Only when ENTER is pressed or another cell is selected, the grid sends the changed value to the worksheet which stores the new cell value in its internal avltree structure and calls the Changed method to notify the visual controls. Some visual controls ignore this cell notification, but the grid and the celledit react by repainting themselves - this is done in the method "ListenerNotification" of the visual controls.

The missing Changed was the reason why the DEL key was not working: the cell was deleted in the worksheet but not told to the grid.
« Last Edit: August 27, 2018, 11:33:15 pm by wp »

Soner

  • Sr. Member
  • ****
  • Posts: 305
Re: TsCustomWorksheetGrid: vk_Back and vk_Delete has not same effect.
« Reply #2 on: August 29, 2018, 11:09:00 am »
Thank you very much for the solution of the problem and for the informations.

 

TinyPortal © 2005-2018