var
MyReg:TRegIniFile;
begin
MyReg:=TRegIniFile.Create;
try
MyReg.OpenKey('MyGridInfo',True);
DBGridEh1.SaveGridLayout(MyReg);
finally
MyReg.CloseKey;
FreeAndNil(MyReg);
end;
end;
//恢复:
var
MyReg:TRegIniFile;
begin
MyReg:=TRegIniFile.Create;
try
MyReg.OpenKey('MyGridInfo',True);
DBGridEh1.RestoreGridLayout(MyReg,[grpColIndexEh, grpColWidthsEh, grpSortMarkerEh, grpColVisibleEh,
grpRowHeightEh, grpDropDownRowsEh, grpDropDownWidthEh]);
finally
MyReg.CloseKey;
FreeAndNil(MyReg);
end;
end;
=====================================================================
procedure TForm1.Button1Click(Sender: TObject);
var
iniFile:TIniFile;
begin
DBGridEh1.SaveGridLayoutIni('C:\test.ini','test',false);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
RestoreParams:TDBGridEhRestoreParams;
begin
RestoreParams:=[grpColIndexEh, grpColWidthsEh, grpSortMarkerEh,
grpColVisibleEh, grpRowHeightEh, grpDropDownRowsEh, grpDropDownWidthEh];
DBGridEh1.RestoreGridLayoutIni('C:\test.ini','test',RestoreParams);
end;
====================================================
procedure TFrmColSelect.SaveGridLayOut;
var
Ini: TIniFile;
begin
if CheckBox1.Checked then
Grid.SaveGridLayoutIni(ExtractFilePath(Application.ExeName) + '\Grid.ini',
Owner.ClassName + '$' + Name, true)
else
begin
Ini := TIniFile.Create(ExtractFilePath(Application.ExeName) + '\Grid.ini');
try
Ini.EraseSection(Grid.Owner.ClassName + '$' + Grid.Name);
finally
Ini.Free;
end;
end;
end;
procedure RestoreGridLayOut(AGrid:TDBGridEh);
var
RestoreParams:TDBGridEhRestoreParams;
begin
RestoreParams:=[grpColIndexEh,grpColWidthsEh,grpSortMarkerEh,
grpColVisibleEh,grpRowHeightEh];
with AGrid do
RestoreGridLayoutIni(ExtractFilePath(Application.ExeName) + '\Grid.ini',
Owner.ClassName + '$' + Name,RestoreParams);
end;
用了以下的办法解决了!! 跟贴就给分!!!
//保存列宽
DBGridEh1.SaveGridLayoutIni(ExtractFilePath(Application.ExeName)
+'ini\'+DBGridEh1.Owner.ClassName+'.ini',
DBGridEh1.Owner.ClassName+'$'+DBGridEh1.Name,true);
showmessage('列状态保存成功!');
end
except
showmessage('列状态保存失败!');
end;