How can I make FNCGrid Columns manually (with GridAdapter).

Hello,
how can I make FNCGrid Columns manually. I don't find it in the manual or in the demos.

I set AutoCreateColumns := False;
I don't want all columns of the DataSet.

I have made this, but it doesn't work

I use this var
  myGrid: TTMSFNCGrid;
  myAdapter: TTMSFNCGridDatabaseAdapter;
  ac: TTMSFNCGridDatabaseAdapterColumn;
  gc: TTMSFNCGridColumn;
//*********************

  myGrid.Columns.Clear;

  myAdapter.DataSource := Viewmodel.DataSource;
  myAdapter.LoadAllDataAndDisconnect;
  myGrid.Adapter := myAdapter;

  for i := 0 to MyColumns.Count-1 do
    if MyColumn[i].Visible then begin
      ac := myAdapter.Columns.Add;
      ac.FieldName := MyColumn[i].FieldName;
      ac.Header    := MyColumn[i].Title;
    end;

  for i := 0 to MyColumns.Count-1 do
    if MyColumn[i].Visible then begin
      gc := myGrid.Columns.Add;
      gc.Name := MyColumn[i].Title;
      gc.FixedFont.Name := MyColumn[i].FontName;
      gc.FixedFont.Size := MyColumn[i].FontSize;
      gc.FixedFont.Color := MyColumn[i].FontColor.toColor;
      gc.Font.Name := MyColumn[i].FontName;
      gc.Font.Size := MyColumn[i].FontSize;
      gc.Font.Color := MyColumn[i].FontColor.toColor;
    end;

  myAdapter.Active := True;

Do you have an example?
Thank you

One more thing, the dataset will be loaded later. This is the initialization. I would like to have this ready in FormCreate.

LoadAllDataAndDisconnect is not required, as well as adding columns to the grid. When AutoCreateColumns is false, only columns need to be added to the database adapter. Then this will reflect in the grid.

I use this var
  myGrid: TTMSFNCGrid;
  myAdapter: TTMSFNCGridDatabaseAdapter;
  ac: TTMSFNCGridDatabaseAdapterColumn;
  gc: TTMSFNCGridColumn;
//*********************
  myAdapter.DataSource := Viewmodel.DataSource;
  myGrid.Adapter := myAdapter;

  for i := 0 to MyColumns.Count-1 do
    if MyColumn[i].Visible then begin
      ac := myAdapter.Columns.Add;
      ac.FieldName := MyColumn[i].FieldName;
      ac.Header    := MyColumn[i].Title;
    end;

  myAdapter.Active := True;

The columns do not appear. Did I forget something or accidentally deactivated it?

After the DataSet gets the data, I set the Adapter to Active.
If I debug this code, the Adapter Columncout is 0. (debugging: Set Active to True)
This is probably the error

Because I tested so much, my configuration (isVisible) was probably changed.
Everything works.
Thanks.

1 Like

Good to read, thanks for the followup!