Recent

Author Topic: Deleting selection  (Read 2879 times)

Vittorio

  • New Member
  • *
  • Posts: 32
Deleting selection
« on: April 18, 2018, 03:31:39 pm »
When I want to delete selected data in WorkSheetGrid by pressing "Del" key it proceeds in two keystrokes: the first one deletes focuced cell in selection, the second deletes remaining cells. Is it possible to do it in one step?

SeregaKR

  • New Member
  • *
  • Posts: 35
Re: Deleting selection
« Reply #1 on: April 18, 2018, 04:10:11 pm »
I think the correct way to do it is following:
-You write the procedure to catch Del keypress (there is OnKeyPress method of the WorkSheetGrid).

On the first keypress you remember the selected cells and increase the counter to 1 (some global variable).
-On the second click you check if it's the same cells and check the counter. If it's not the same cells you change the counter to 1 and change recorded range to current. If it's the same cell you delete worksheetgrid contents and change counter value to 0.

Unfortunately I'm not sure how to find out what cells are selected now. For one cell you can use TsCellIndicator but for many I'm not sure. If WorkSheetGrid is similar to TStringGrid then you can record for cells in for corners of the selection. Try looking here: https://stackoverflow.com/questions/12807687/sum-value-of-selected-cells-in-stringgrid
« Last Edit: April 18, 2018, 04:17:47 pm by SeregaKR »

wp

  • Hero Member
  • *****
  • Posts: 11830
Re: Deleting selection
« Reply #2 on: April 19, 2018, 10:39:36 pm »
The grid of the current svn revision is able to delete a cell block at once; this works also for several blocks in case of multi-selection. There's no need any more to do this manually.

As for the selected cells, here are the related worksheet methods:

Code: Pascal  [Select][+][-]
  1. type
  2.   TsCellRange = record
  3.     Row1, Col1, Row2, Col2: Cardinal;
  4.   end;
  5.  
  6.   TsCellRangeArray = array of TsCellRange;
  7.  
  8.   TsWorksheet = class
  9.     ...
  10.     procedure SelectCell(ARow, ACol: Cardinal);
  11.     procedure ClearSelection;
  12.     procedure DeleteSelection;
  13.     function GetSelection: TsCellRangeArray;
  14.     function GetSelectionAsString: String;
  15.     function GetSelectionCount: Integer;
  16.     function GetSelectionRangeIndexOfActiveCell: Integer;
  17.     procedure SetSelection(const ASelection: TsCellRangeArray);  

 

TinyPortal © 2005-2018