TTMSFNCGrid Column Visibility Revisted

So while the grid doesn't support Column.Visible yet I tried a work around like this:

Procedure TMyForm.AddColumn;
var Col: TTMSFNCGridDatabaseAdapterColumn;
begin
   GridAdapter.BeginUpdate;
   Try
       Col := GridAdapter.Columns.Add;
       FColIndex := Col.Index;
       Col.FieldName := 'AFieldName';
      Col.Header := 'Col Title';
   Finally
      GridAdapter.EndUpdate; 
End;
end;

And then

Procedure TMyForm.DeleteColumn;
begin
   GridAdapter.BeginUpdate;
   Try
       GridAdapter.Columns.Delete(FColIndex);
   Finally
      GridAdapter.EndUpdate; 
End;
end;

The first call works (although I have to set the column width). But the second call doesn't remove the column. I have tried various Update methods on the Grid but nothing seems to work.

Any ideas?

Thanks

Hi,

To manually add columns you need to set GridAdapter.AutoCreateColumns to False; Additionally, the columns of the adapter are mapped on the grid when the Active property is set. Only once. So to remove columns, you need to remove the column at dataset adapter level and then remove it at grid level as well, or toggle the Active property.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.