3
votes

I'm writing a FMX program in XE4 using the TGrid class. I want to extract the value from a particular column of the row I double clicked in a TGrid. The grid was loaded with strings from a database table (using live binding).

For example, say the TGrid displays 5rows x 10columns, and I'm interested in the values in column 9. If I double click anywhere in row 2, I want the value of cell(row=2, col=9) to be put in a TEdit.

I may be looking at things simplistically, but in TGrid I did not find any function that can get me a cell value based on its (row,col).

2

2 Answers

4
votes

You can use the protected method GetValue.

function GetValue(Col, Row: Integer): TValue; virtual;

Then using the ColumnIndex and Selected properties you can get the current col and row.

Try this

type 
  TGridClass=class(TGrid);

procedure TForm1.Grid1DblClick(Sender: TObject);
begin
  ShowMessage(TGridClass(Sender).GetValue(TGrid(Sender).ColumnIndex, TGrid(Sender).Selected).ToString);
end;
0
votes

Or you can use something like

Grid1.Columns[Col].Controls[Row]