Is it possible to get the Field-Value from TTMSFNCDataGridDatabaseAdapter in the TTMSFNCDataGrid.OnGetCellLayout
This would be really handy for defining formatting conditions externally based on database values instead of displayed values.
Is it possible to get the Field-Value from TTMSFNCDataGridDatabaseAdapter in the TTMSFNCDataGrid.OnGetCellLayout
This would be really handy for defining formatting conditions externally based on database values instead of displayed values.
Hi, you can use the following code to achieve the behavior your looking for. The code is based on the BioLife.xml (TClientDataSet)
procedure TForm1.TMSFNCDataGrid1GetCellLayout(Sender: TObject;
ACell: TTMSFNCDataGridCell);
var
o: Integer;
begin
if not Assigned(TMSFNCDataGridDatabaseAdapter1) or not TMSFNCDataGridDatabaseAdapter1.CheckDataSet then
Exit;
o := TMSFNCDataGridDatabaseAdapter1.DataLink.ActiveRecord;
try
if TMSFNCDataGridDatabaseAdapter1.SetActiveRecord(ACell.Row) then
begin
if TMSFNCDataGridDatabaseAdapter1.ColumnAtField['Category'].Field.AsString = 'Shark' then
ACell.Layout.Font.Color := gcRed;
end;
finally
TMSFNCDataGridDatabaseAdapter1.DataLink.ActiveRecord := o;
end;
end;
This works great if you are using the field values within the dataset, However, if I need to check the qty from inventory and if qty are not there make that row red, I try to use the following code but it has a performance issue.
procedure TBOMForm.WOITEMSDATAGRIDGetCellLayout(Sender: TObject;
ACell: TTMSFNCDataGridCell);
var
ar, c, r: Integer;
TOTON : DOUBLE;
begin
if ACELL.row < WOITEMSDATAGRID.FixedRowCOUNT then
begin
Acell.Layout.TextAlign := TTMSFNCGraphicsTextAlign.gtaCenter;
Acell.layout.Font.Style := [tfontstyle.fsUnderline,tfontstyle.fsBold];
Acell.layout.Font.Size := 15;
end
else
begin
Acell.layout.Font.Style := [tfontstyle.fsBold];
Acell.layout.Font.Size := 11;
end;
R := 0;
if not Assigned(WOITEMSDATAGridDatabaseAdapter) or not WOITEMSDATAGridDatabaseAdapter.CheckDataSet then
Exit;
r := WOITEMSDATAGridDatabaseAdapter.DataLink.ActiveRecord;
try
if WOITEMSDATAGridDatabaseAdapter.SetActiveRecord(ACell.Row) then
begin
if (WOITEMSDATAGridDatabaseAdapter.ColumnAtField['TYPE'].Field.AsString = 'Raw Good') THEN
BEGIN //FDQUERY4 IS USING A STORED PROCEDURE TO GET QTY ON HAND
FDQUERY4.Close;
FDQUERY4.ParamByName('LG').AsString := 'Vicksburg';
FDQUERY4.ParamByName('PID').AsInteger := WOITEMSDATAGridDatabaseAdapter.ColumnAtField['PARTID'].Field.AsInteger;
FDQUERY4.Open;
if fdquery4.RecordCount > 0 then
TOTON := FDQUERY4.FieldByName('QTYONHAND').AsFloat
else
TOTON := 0;
FDQUERY4.Close;
IF (WOITEMSDATAGridDatabaseAdapter.ColumnAtField['QTYTARGET'].Field.ASFLOAT > TOTON) then
ACELL.Layout.Fill.Color := tAlphaColorRec.Red
ELSE
ACELL.Layout.Fill.Color := tAlphaColorRec.lightgreen;
END
else
exit;
end;
finally
WOITEMSDATAGridDatabaseAdapter.DataLink.ActiveRecord := r;
end;
.
Thanks still learning Datagrid
Garnett
The performance issue comes from fetching the columns (ColumnAtField), you might want to determine the column once after the dataset is set active, and then use that column to retrieve the field. Or use the fields from the dataset directly.