TAdvStringGrid
Example 88 : Persist column state in an INI file and allow column selection via a column picker
Drop a TAdvStringGrid and TAdvGridColumnPicker on the form and add following code:
procedure TForm4.FormCreate(Sender: TObject); var s: string; ini: TINIFile; begin AdvStringGrid1.LinearFill(true); AdvStringGrid1.SetColumnOrder; AdvStringGrid1.Options := AdvStringGrid1.Options + [goColMoving, goColSizing]; AdvGridColumnPicker1.Grid := AdvStringGrid1; ini := TINIFile.Create('.\gridsettings.ini'); s := ini.ReadString('GRID','SETTINGS', ''); ini.Free; if s <> '' then begin AdvStringGrid1.StringToColumnStates(s); AdvGridColumnPicker1.Init; end; end;
In the form constructor, we are reloading the persisted settings for column with, position, visibility from the INI file and initializing grid and column picker with these settings.
procedure TForm4.FormClose(Sender: TObject; var Action: TCloseAction); var s: string; ini: TINIFile; begin s := AdvStringGrid1.ColumnStatesToString; ini := TINIFile.Create('.\gridsettings.ini'); ini.WriteString('GRID','SETTINGS', s); ini.Free; end;
×