mm gg
mm gg

Reputation: 31

Delphi XE4 TGrid how do I get the value of a cell in the row I double clicked?

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).

Upvotes: 3

Views: 5241

Answers (2)

LHristov
LHristov

Reputation: 1123

Or you can use something like

Grid1.Columns[Col].Controls[Row]

Upvotes: 0

RRUZ
RRUZ

Reputation: 136391

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;

Upvotes: 4

Related Questions