Reputation: 31
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
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