Is there anyway to determine which rows are currently selected in a multi-select TStringGrid
, or a TCustomGrid
for that matter. A property would be ideal.
I know that there is the gdSelected
property that gets set in the DrawCell
event,
procedure DrawCell(ACol, ARow: Longint; ARect: TRect; AState: TGridDrawState);
I can check AState
for gdSelected
, and keep track of this in an array somewhere, but this seems kludgey.
Use string grid selection property
StringGrid.Selection.top
will give you the top selected row,StringGrid.Selection.bottom
will give you the end selected row, where the selection stops.Example:
If you select from row 3 to row 6 in a string grid then
StringGrid.Selection.top
will give you 3 as an output valueStringGrid.Selection.bottom
will give you 6 as an output value, and remaining values you can get by iterating from the top to bottom.Oooh, I'm use
StringGrid.Selection.BottomRight.Y
to determine rows andStringGrid.Selection.BottomRight.X
for columns.I guess you are talking about a range-select string grid, that is, a string grid with
goRangeSelect
inOptions
. Then you can use theSelection
property. This is (essentially) aTRect
in which you can find the upper-left and lower-right cell in the range selection.