Delphi 11.1 FNC Grid On

Hello,

I have a grid and try to color a row depending on the value of a certain cell.

in the OnGetCellLayout event i have the folowing code

if FNCGridBegroting.AllFloats[2,ARow] = 1 then
begin
aLayout.Font.Color := System.UITypes.TAlphaColorRec.Blue;
end;

The grid is connected to a FDMemTable with records in it.
The text color is never coloring blue.

Only if i manually type the value again in the grid the row colors Blue.

What am I missing ?

Gert Hoogeboom

This is because the value is not stored in the grid when connecting it via a database adapter. You need to access the value directly. Please check the following sample

procedure TForm1.TMSFNCGrid1GetCellLayout(Sender: TObject; ACol, ARow: Integer;
  ALayout: TTMSFNCGridCellLayout; ACellState: TTMSFNCGridCellState);
var
  activeRecord, c, i: Integer;
  monChamp: TField;
  maGrille: TTMSFNCGrid;
  monAdaptateurGrille: TTMSFNCGridDatabaseAdapter;
  o: Integer;
begin

  maGrille := TTMSFNCGrid(Sender);
  if (ARow <= maGrille.FixedRows - 1) then
    Exit;

  c := ACol - maGrille.FixedColumns;

  if (c >= 0) and (c <= maGrille.Columns.Count - 1) then
  begin
    monAdaptateurGrille := TTMSFNCGridDatabaseAdapter
      (TMSFNCGridDatabaseAdapter1);
    if monAdaptateurGrille.CheckDataSet then
    begin
      activeRecord := monAdaptateurGrille.DataLink.activeRecord;
      try
        o := monAdaptateurGrille.DataLink.ActiveRecord;

        monAdaptateurGrille.SetActiveRecord(ARow);

        if (monAdaptateurGrille.DataLink.ActiveRecord < 0) or ((monAdaptateurGrille.DataLink.ActiveRecord >= monAdaptateurGrille.DataLink.BufferCount) and
          not ((monAdaptateurGrille.DataLink.ActiveRecord = monAdaptateurGrille.DataLink.BufferCount) and (monAdaptateurGrille.DataSetType = adsNonSequenced))) then
        begin
          monAdaptateurGrille.DataLink.ActiveRecord := o;
          Exit;
        end;

        monChamp := monAdaptateurGrille.FieldAtColumn[3];
        if Assigned(monChamp) then
        begin
          i := 0;
          if TryStrToInt(monChamp.AsString, i) then
          begin
            if i > 50000 then // ou autre chose
            begin
              ALayout.Fill.Color := gcRed;
            end;
          end;
        end;
      finally
        monAdaptateurGrille.DataLink.activeRecord := activeRecord;
      end;
    end;
  end;
end;

Oke this works, i would think dat is was al little easier.

What if i would like to clear a complete cell depending on a certain value of a field.
The old code i the FMX Grid was
grlBegroting.Cells[4,ARow] :='';

You should use the dataset directly to clear a field value instead, which will reflect in the grid. There is currently no interface available to programmatically clear a value in the grid. We are discussing this here and might in the future, redesign the database link to properly integrate programmatic and visual actions in the grid