Link to home
Start Free TrialLog in
Avatar of arocio
arocio

asked on

changing the width columns

A client is having some problems working the component DBGrid. He has some fields that are smaller
                  or bigger than the default width columns so he enter to the Columns editor and change the property
                  width, and the columns changes, but if he saves and close the Delphi, restart Delphi and reopen the
                  project the columns are with the default width, again.

                  So he has kept the columns with that size but the interface isn't OK, because there are grids with 50
                  columns.

                  Do you know anything about it ??
Avatar of TheNeil
TheNeil

You could save the column widths in a file and simply load them at run time. That way whenever the user changes the column width at runtime you can save the column widths to the file and next time it runs theye are exactly as he/she left them

The Neil
Is the width of the column header/title, less than the width he is setting the column to?
ASKER CERTIFIED SOLUTION
Avatar of DrDelphi
DrDelphi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kretzschmar
to drdelphi,

>Good luck!!

yup, i guess this is needed,
because is the field is empty then will the width be 0 :-(


better would be something like this
dbgrid1.columns[index].Width := dbgrid1.columns[index].Field.Displaywidth; //+ maybe a bit additional offset

but the best solution is already commented by the neil by storing the width by iterating through the columns in a file at app-end and read and set at app start, then the client can do what he want with the grid-column width.

meikl
Avatar of arocio

ASKER

Well, the point isn't like that, because the problem is that never it keeps the width the developer gives.
I will ammend my answer to suit :

var I:integer;
begin
For I:=0 to 3 do
if length(Fields[i].AsString)>20
  then Fields[i].DisplayWidth:=Length Fields[i].AsString)
Else
  Fields[i].DisplayWidth:=20;
end;



This will give you a set minimun width, changing only when the field requires it.


Good luck!!