用鼠标调整dbgrid列的位置后,保存,下次打开程序能够显示保存后的排列顺序

解决方案 »

  1.   

    大概是保存在ini文件中﹐form打開關閉時讀或寫進ini文件
      

  2.   

    我想是应该找到字段和位置的对应关系,
    但是dbgrid没有字段名的信息,只有title,而title的caption属性是可以重复的
      

  3.   

    改动列时保存到INI文件中,
    打开时从INI文件中读取
      

  4.   


      with DBGEh do
      begin
        for i:=0 to Columns.Count-1 do
          if Columns[i].Field<>nil then
            with Columns[i] do
            begin
              tmp:=tmp+FieldName+',';
              Params.Values[Fieldname+csLabel]:=Title.Caption;
              Params.Values[FieldName+csIndex]:=IntToStr(i);
              Params.Values[FieldName+csAlign]:=csAlignValues[Alignment];
              if Visible then
                Params.Values[FieldName+csVisible]:='1'
              else
                Params.Values[FieldName+csVisible]:='';
              Params.Values[FieldName+csWidth]:=IntToStr(Width{Width_ColumnEhToField(DBGEh,Width)});
              Params.Values[FieldName+csFT_Value]:=Footer.Value;
              Params.Values[FieldName+csFT_ValueType]:=csFT_ValueTypes[Footer.ValueType];
              Params.Values[FieldName+csMinWidth]:=IntToStr(MinWidth);
              Params.Values[FieldName+csMaxWidth]:=IntToStr(MaxWidth);          Params.Values[FieldName+csEh_Title+csFont_Name]:=Title.Font.Name;
              Params.Values[FieldName+csEh_Title+csFont_Size]:=IntToStr(Title.Font.Size);
              Params.Values[FieldName+csEh_Title+csFont_Color]:=IntToStr(Title.Font.Color);
              Params.Values[FieldName+csEh_Title+csFont_Style]:=GetFontStyle(Title.Font);          Params.Values[FieldName+csEh_Data+csFont_Name]:=Font.Name;
              Params.Values[FieldName+csEh_Data+csFont_Size]:=IntToStr(Font.Size);
              Params.Values[FieldName+csEh_Data+csFont_Color]:=IntToStr(Font.Color);
              Params.Values[FieldName+csEh_Data+csFont_Style]:=GetFontStyle(Font);          Params.Values[FieldName+csEh_Footer+csFont_Name]:=Footer.Font.Name;
              Params.Values[FieldName+csEh_Footer+csFont_Size]:=IntToStr(Footer.Font.Size);
              Params.Values[FieldName+csEh_Footer+csFont_Color]:=IntToStr(Footer.Font.Color);
              Params.Values[FieldName+csEh_Footer+csFont_Style]:=GetFontStyle(Footer.Font);          Params.Values[FieldName+csEh_Title+csFont_BColor]:=IntToStr(Title.Color);
              Params.Values[FieldName+csEh_Data+csFont_BColor]:=IntToStr(Color);
              Params.Values[FieldName+csEh_Footer+csFont_BColor]:=IntToStr(Footer.Color);
            end;
        Params.Values[csFields]:=tmp;
      

  5.   

    大概就用以上的方法保存。
    try
          CommaText:=Params.Values[csFields];
          for i:=0 to Count-1 do
          begin
            tmpName:=Strings[i];
            if tmpName='' then Continue;
            tmp1:=DBGEh.Columns.Add;
            tmp2:=nil;   //保持装载列原有的属性不变
            for n:=0 to DBGEh.Columns.Count-1 do
              if (DBGEh.Columns[n]<>tmp1) and
                 (DBGEh.Columns[n].FieldName=tmpName) then
              begin
                tmp2:=DBGEh.Columns[n];
                Break;
              end;
            if tmp2<>nil then
              tmp1.Assign(tmp2);
            with tmp1 do  //仅改变保存的属性
            begin
              FieldName:=tmpName;
              if Params.Values[FieldName+csVisible]='1' then
                Visible:=True
              else
                Visible:=False;
              Width:=StrToIntDef(Params.Values[FieldName+csWidth], 10);//Width_FieldToColumnEh(DBGEh, StrToIntDef(Params.Values[FieldName+csWidth], 10));
              Title.Caption:=Params.Values[FieldName+csLabel];
              if Field<>nil then
                Field.DisplayLabel:=Title.Caption;