3

Does anyone know how to unselect cell in a FireMonkey TStringgrid (in other words, i need to know which cell is selected and how to unselect)...?

We are using Delphi Berlin 10.1

Thanks in advance.

Jande
  • 1,695
  • 2
  • 20
  • 32
  • The `Selected` property gives the selected row index. The `ColumnIndex` property gives the selected column. I cannot find a way to unselect other than selecting another cell. See [Delphi XE4 stringgrid selectcell in FireMonkey](http://stackoverflow.com/q/17808168/576719) – LU RD Jan 18 '17 at 10:45

1 Answers1

3

To get currently selected row, use Selected property. To get currently selected column, use ColumnIndex property. Row and column indices start at 0,

To unselect you can choose to set Selected and ColumnIndex to f. ex. -1.

Tested with this code:

procedure TForm29.Button1Click(Sender: TObject);
var
  SelRow, SelCol: integer;
begin
  SelRow := StringGrid1.Selected;
  SelCol := StringGrid1.ColumnIndex;
  Memo1.Lines.Add(Format('SelRow: %d, SelCol: %d',[SelRow, SelCol]));
  StringGrid1.Selected := -1;
  StringGrid1.ColumnIndex := -1;
  SelRow := StringGrid1.Selected;
  SelCol := StringGrid1.ColumnIndex;
  Memo1.Lines.Add(Format('SelRow: %d, SelCol: %d',[SelRow, SelCol]));
end;
Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54