Is there a way to create a row indicator in the first column of a TTMSFNCGrid, similar to the one in TDBGrid? It would need to be a triangle when in browse mode and an asterisk in edit and insert mode.
Hi, you should be able to accomplish this using the following code:
procedure TForm54.ClientDataSet1BeforeInsert(DataSet: TDataSet);
begin
FOldRec := ClientDataSet1.RecNo;
TMSFNCGrid1.Repaint;
end;
procedure TForm54.TMSFNCGrid1CellAfterDraw(Sender: TObject; ACol, ARow: Integer;
AGraphics: TTMSFNCGraphics; ARect, ATextRect: TRectF);
var
pth: TTMSFNCGraphicsPath;
begin
if ((ARow = ClientDataSet1.RecNo) or (ClientDataSet1.RecNo = -1)) and (ACol = 0) then
begin
if (ClientDataSet1.State = dsInsert) then
begin
if (FOldRec = ARow - 1) then
AGraphics.DrawText(ARect, '*', False, gtaTrailing, gtaCenter)
end
else
begin
pth := TTMSFNCGraphicsPath.Create;
try
pth.MoveTo(PointF(ARect.Right - 5, ARect.Top + ARect.Height / 2));
pth.LineTo(PointF(ARect.Right - 15, ARect.Top + 5));
pth.LineTo(PointF(ARect.Right - 15, ARect.Top + ARect.Height - 5));
pth.ClosePath;
AGraphics.Fill.Color := gcBlack;
AGraphics.Fill.Kind := gfkSolid;
AGraphics.Stroke.Color := gcBlack;
AGraphics.Stroke.Kind := gskSolid;
AGraphics.DrawPath(pth);
finally
pth.Free;
end;
end;
end;
end;
Pieter,
Thanks for the swift reply. It got me off to a good start and I ended up making some tweaks to support centering the indicator and having it show an asterisk when a row is edited. Here is the revised code. FYI, I used a FDMemTable instead of a ClientDataset:
procedure TForm3.FDMemTable1BeforeEdit(DataSet: TDataSet);
begin
FOldRec := FDMemTable1.RecNo;
TMSFNCGrid1.Repaint;
end;
procedure TForm3.FDMemTable1BeforeInsert(DataSet: TDataSet);
begin
FOldRec := FDMemTable1.RecNo;
TMSFNCGrid1.Repaint;
end;
procedure TForm3.TMSFNCGrid1CellAfterDraw(Sender: TObject; ACol, ARow: Integer;
AGraphics: TTMSFNCGraphics; ARect, ATextRect: TRectF);
var
pth: TTMSFNCGraphicsPath;
IndicatorRight: Single;
begin
if ((ARow = FDMemTable1.RecNo) or (FDMemTable1.RecNo = -1)) and (ACol = 0) then
begin
if (FDMemTable1.State in [dsInsert, dsEdit]) then
begin
if ((FDMemTable1.RecordCount = 0) and (ARow = 0)) then Exit;
if ((FDMemTable1.RecordCount = 0) and (FOldRec = ARow - 1)) or (FOldRec = ARow) then
AGraphics.DrawText(ARect, '*', False, gtaCenter, gtaCenter)
end
else
begin
if FDMemTable1.RecordCount = 0 then Exit;
pth := TTMSFNCGraphicsPath.Create;
try
IndicatorRight := ARect.Right - (ARect.Width - 15)/2;
pth.MoveTo(PointF(IndicatorRight - 5, ARect.Top + ARect.Height / 2));
pth.LineTo(PointF(IndicatorRight - 15, ARect.Top + 5));
pth.LineTo(PointF(IndicatorRight - 15, ARect.Top + ARect.Height - 5));
pth.ClosePath;
AGraphics.Fill.Color := gcBlack;
AGraphics.Fill.Kind := gfkSolid;
AGraphics.Stroke.Color := gcBlack;
AGraphics.Stroke.Kind := gskSolid;
AGraphics.DrawPath(pth);
finally
pth.Free;
end;
end;
end;
end;
You should be aware, however, of what seems to be a bug in the Grid. The grid works fine so long as I insert a record at row 1. If I attempt to insert a record anywhere else, the blank row for the insert does not display.
Hi Terry,
Thank you for the updated code.
We are aware that there are some shortcomings regarding database support in FNC. We have this on our planning, to be looked at real soon.
You're welcome, Pieter. Hopefully, as you fix bugs in the component you will also consider making the display of an indicator a grid option the user can set at design time.