Frequently Asked Component Specific Questions
Options |
|
Display all FAQ items |
Displaying items 1 to 1 of 1, page 1 of 1
<< previous next >>

TDBAdvGridPersisting column sizes & column order for a TDBAdvGrid
Assuming a user can resize & move columns around in a TDBAdvGrid and it is desirable that the last state is saved & restored when the application is restarted, this can be done in following way:
- Set default column order & size state after making the dataset active in the TDBAdvGrid with grid.SetColumnOrder
- When column states are found, restore these from INI file with grid.StringToColumnStates
- When the application closes, save the last state to INI file with grid.ColumnStatesToString
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
var
inif: TINIFile;
begin
inif := TINIFile.Create('.\settings.ini');
inif.WriteString('STATES','DBADVGRID1',DBAdvGrid1.ColumnStatesToString);
inif.Free;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
inif: TINIFile;
colstates: string;
begin
adotable1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\CARS.mdb;Persist Security Info=False';
adotable1.Active := true;
DBAdvGrid1.SetColumnOrder;
DBAdvGrid1.Options := DBAdvGrid1.Options + [goColSizing, goColMoving];
inif := TINIFile.Create('.\settings.ini');
colstates := inif.ReadString('STATES','DBADVGRID1','');
inif.Free;
if colstates <> '' then
DBAdvGrid1.StringToColumnStates(colstates);
end;