Recent

Author Topic: [SOLVED] Is there a selected property for cells in a stringgrid?  (Read 1199 times)

wittbo

  • Full Member
  • ***
  • Posts: 150
I'm looking for an easy way to count the number of selected cells in a stringgrid.
Is there anything like a selected property for each cell?
« Last Edit: March 31, 2020, 12:08:45 am by wittbo »
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Is there a selected property for cells in a stringgrid?
« Reply #1 on: March 30, 2020, 03:57:38 pm »
To know if a cell is selected you can use
  AGrid.IsCellSelected(x, y)
If instead you want to get the range of selected cells, use
  AGrid.Selection
which returns a TGridRect with the coordinates of the selected "rectangle".

Or, if you have multi-range selections active, you can use:
  AGrid.SelectedRange[Index]
along with
  AGrid.SelectedRangeCount


HTH!
« Last Edit: March 30, 2020, 04:07:47 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

wittbo

  • Full Member
  • ***
  • Posts: 150
Re: Is there a selected property for cells in a stringgrid?
« Reply #2 on: March 30, 2020, 08:16:05 pm »
Thanks, Lucamar, for this tip.
Meanwhile I made a little routine for counting the selected rows (if rowselect=true). s.b.

Code: Pascal  [Select][+][-]
  1. function SelectedRowCount (theGrid: TStringGrid): Integer;
  2. var i     : Integer;
  3.     iCount: Integer;
  4. begin
  5.    iCount := 0;
  6.    for i:=0 to theGrid.SelectedRangeCount-1 do
  7.       iCount := iCount + 1 + theGrid.SelectedRange[i].Bottom - theGrid.SelectedRange[i].Top;
  8.    SelectedRowCount := iCount
  9. end;
-wittbo-
MBAir with MacOS 10.14.6 / Lazarus 2.2.4
MacStudio with MacOS 13.0.1 / Lazarus 2.2.4

 

TinyPortal © 2005-2018