ColumnStatesToString problem

DBAdvGrid version 2.3.6.27


Code sections:

implementation
{$R *.dfm}
var s : string;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
...
    Ini.WriteString('Grid','Settings',DBAdvGrid1.ColumnStatesToString);
...
end;

procedure TForm1.FormShow(Sender: TObject);
...
    s := Ini.ReadString('Grid','Settings','');
...
  DBAdvGrid1.SetColumnOrder;
end;

procedure TForm1.RunNowBtnClick(Sender: TObject);
...
  DBAdvGrid1.ResetColumnOrder;
  DBAdvGrid1.Clear;  // in case the user has run a request before, clear the results out
... 
    try
      ADOConnection1.Connected := true;
    except
      raise Exception.Create('Unable to connect to server!');
    end;
    ADOQuery1.Open;
    if s<>'' then
      DBAdvGrid1.StringToColumnStates(s);
  end;
end;


DBAdvGrid is defined with 16 columns, 1 fixed row.  Headers are defined, ADOQuery is "prepared".

On first execution, with no GRID section in the INI file, all 16 columns show up, with multiple rows.  Exit the program.  Run the program again.  When the StringToColumnStates section is executed, the DBGrid reduces to 2 columns!

The value in the INI file shows to be:
[Grid]
Settings=2#70,70#0,1#1,1

I expected it to be:
[Grid]
Settings=16#70,70,70,70,70,70,70,70,70,70,70,70,70,70,70,70#0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15#1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1

I have searched the program, and variable S is only used in the code sections above.

I used the AdvStringGrid manual pages 158, 159 to work out persisting the column order, as the user wants to rearrange them.  The options are set for goColMoving and goColSizing in the component, not in code.

I do not understand why the DBGrid is behaving this way.

Anyone have a solution / insight?

Thank you.

Adding this code to the program results in the INI value being saved correctly.  It is only a test to prevent corrupt information from loading.  It is inserted between the INI read and the SetColumnOrder in the OnFormShow event.


  if length(s) > 1 then
  begin
    if Copy(s,1,2)<>'16' then
      s := '';
  end;

I have no idea as to what the problem is or how it was caused. This does not make sense.

What are your setting for grid.AutoCreateColumns / grid.AutoRemoveColumns?

Can you try to set these to false?

Both were set to true.  The behavior appears to be gone, having upgraded to version 2.3.7.0 of the DBAdvGrid in the March 3, 2015 release.  Setting to false seems to have no apparent effect at this time.


Can you elaborate on the purpose of AutoCreateColumns and AutoRemoveColumns?  I understand the basic words, but want to have an understanding of the intent.  I do not have the luxury of time to read through the source code.  Wish I did. 

From the TDBAdvGrid PDF developers guide:


To get started with TDBAdvGrid, the easiest way is to drop a TDataSource on the form and connect
it to a TDataSet of choice. Activate the dataset and connect the TDataSource to TDBAdvGrid. With
the default setting of TDBAdvGrid.AutoCreateColumns as true, the grid will automatically create
TDBGridColumnItem instances for every DB field in the dataset and add it to the Columns collection.
The TDBGridColumnItem.FieldName will be initialized with the fieldnames found in the dataset
Fields collection. When TDBAdvGrid.AutoRemoveColumns is set to true, deactivating the dataset
will automatically remove all columns from the grid. 

Thanks.  I missed that in the PDF.  Time to get the eyes checked.