Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-10

How to save dbgrid comlumns state?

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Petr, OK2CQR

Hi,

I'd like to save column position, visible and with in DBGrid. In Delphi I use this:

for J:= 0 to Grid.Columns.Count - 1 do
begin
  Section:= Form.Name;
  Ident:= Grid.Name + ' ' + Grid.Columns[J].FieldName;
  Grid.Columns[J].Width:= StrToInt(Ini.ReadString(Section, Ident + '
Width', IntToStr(Grid.Columns[J].Width)));
  Grid.Columns[J].Index:= StrToInt(Ini.ReadString(Section, Ident + '
Index', IntToStr(Grid.Columns[J].Index)));
end;

But this doesn't work in Lazarus because TDBgrid doesn't have FieldName property.

I tried this in Lazarus:

Grid := (Form.Components[I] as TDBGrid);
for J:= 0 to Grid.Columns.Count - 1 do
begin
  Section := Form.Name;
  Ident   := Grid.Name + ' ' + Grid.Columns[J].DisplayName;
  Grid.Columns[J].Width := StrToInt(Ini.ReadString(Section, Ident + '
Width', IntToStr(Grid.Columns[J].Width)));
 Grid.Columns[J].Index := StrToInt(Ini.ReadString(Section, Ident + '
Index', IntToStr(Grid.Columns[J].Index)));
end;

It works fine until user move field to another position.

How do you solve this? Thanks for help.

Petr

Reply by email