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).
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;
或者你可以使用类似的东西
Grid1.Columns[Col].Controls[Row]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.