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;
-----------------------------------------------------------------------------------------------------------------
var RestoreParams:TDBGridEhRestoreParams; begin RestoreParams:=[grpColIndexEh, grpColWidthsEh, grpSortMarkerEh,grpColVisibleEh, grpRowHeightEh, grpDropDownRowsEh, grpDropDownWidthEh]; DBGridEh1.RestoreGridLayoutIniExtractFilePath(Application.ExeName) + '\ini\'+Grid.Owner.ClassName+'.ini', Grid.Owner.ClassName + '$' + Grid.Name,RestoreParams);
上面打错了,把DBGridEh1换成Grid var RestoreParams:TDBGridEhRestoreParams; begin //RestoreParams里设置恢复的内容 RestoreParams:=[grpColIndexEh, grpColWidthsEh, grpSortMarkerEh,grpColVisibleEh, grpRowHeightEh, grpDropDownRowsEh, grpDropDownWidthEh]; //从INI文件里恢复 Grid.RestoreGridLayoutIniExtractFilePath(Application.ExeName) + '\ini\'+Grid.Owner.ClassName+'.ini', Grid.Owner.ClassName + '$' + Grid.Name,RestoreParams);
1) 保存DBGridEH的columns信息 DBGridEH1.SaveGridLayoutIni(‘D:\ DBGridEhGrid.ini’,'Grid',false); 2)对DBGridEh的columns布局信息进行恢复 var RestoreParams:TDBGridEhRestoreParams; begin RestoreParams:=[grpColIndexEh, grpColWidthsEh, grpSortMarkerEh, grpColVisibleEh, grpRowHeightEh, grpDropDownRowsEh, grpDropDownWidthEh]; DBGridEh1.RestoreGridLayoutIni(‘D:\ DBGridEhGrid.ini’,'Grid',RestoreParams);
------------------------------------------------
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;
本文来自博客园,作者:del88,转载请注明原文链接:https://www.cnblogs.com/del88/archive/2013/04/07/3006414.html