最好哪个有代码贴个给小弟看看。谢谢!

解决方案 »

  1.   

    把DBGrid的各列宽度存入ini文件中,下次开启窗体的时候从ini文件读取DBGrid的数据
      

  2.   

    俺的函数库中正好有这两个函数
    procedure f_ReadIni(const Now_DBGrid:TDBGrid;Form_Name:String);
    var
      FilePath:String;
      MyIniFile:Tinifile;
      Grid_Name,Field_Name:String;
      Width:integer;
      i,j,n:integer;
      Column:Array[0..100] of String;
      Widths:Array[0..100] of integer;
    begin
      FilePath := ExtractFilePath(Application.ExeName);
      MyIniFile:=TiniFile.Create(FilePath+'gsp.ini');
      Grid_Name :=Form_Name+','+Now_DBGrid.Name;
      n:= Now_DBGrid.Columns.Count-1 ;  for i:=0 to 100 do column[i]:='';
      for i:=0 to n do
      begin
        Field_Name:=Now_DBGrid.Columns[i].FieldName;
        j:=MyIniFile.ReadInteger(Grid_Name,Field_Name,i);
        Column[j]:=Field_Name;
        Widths[j] :=MyIniFile.ReadInteger(Grid_Name,Field_Name+'_Width',Now_DBGrid.Columns[i].Width);
      end;  for i:=0 to n do
      begin
        Now_DBGrid.Columns[i].FieldName := Column[i];
        Now_DBGrid.Columns[i].Width := Widths[i];
      end;  MyIniFile.Destroy;
    end;procedure f_WriteIni(const Now_DBGrid:TDBGrid;Form_Name:String);
    var
      FilePath:String;
      MyIniFile:Tinifile;
      Grid_Name,Field_Name:String;
      Width:Integer;
      i:integer;
    begin
      FilePath := ExtractFilePath(Application.ExeName);
      MyIniFile:=TiniFile.Create(FilePath+'gsp.ini');
      Grid_Name :=Form_Name+','+Now_DBGrid.Name;  for i:=0 to Now_DBGrid.Columns.Count-1 do
      begin
        Field_Name := Now_DBGrid.Columns[i].FieldName;
        Width := Now_DBGrid.Columns[i].Width;
        MyIniFile.WriteInteger(Grid_Name,Field_Name,i);
        MyIniFile.WriteInteger(Grid_Name,Field_Name+'_Width',Width);
      end;  MyIniFile.Destroy;
    end;