取DBGRID内一个单元格内的值

时间:2021-07-08 19:30:09
type
  TDBGridEx = class(TDBGrid)
    function GetValue(row, col: integer):Variant;
  end;
function TDBGridEx.GetValue(row, col: integer): Variant;
begin
  // TDBGrid有行列索引,但它们是protected的
  self.Row := row;
  self.Col := col;
  Result := self.SelectedField.AsVariant;
end;

 
设置当前行应该用如下:
  self.DataSource.DataSet.First;
  self.DataSource.DataSet.MoveBy(row);
  self.Col := col;
注意异常处理