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 ??
arocioAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheNeilCommented:
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
0
VendiCommented:
Is the width of the column header/title, less than the width he is setting the column to?
0
DrDelphiCommented:
Try this out.. it's sneaky, but it does the job:

var colwidth:integer;
begin
   ColWidth:=Dbgrid1.Canvas.TextWidth(stringofchar('8',length(Dbgrid1.Columns[0].Field.AsString)));
   Dbgrid1.Columns[0].Width:=colWidth;
end;


Good luck!!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fundamentals of JavaScript

Learn the fundamentals of the popular programming language JavaScript so that you can explore the realm of web development.

kretzschmarCommented:
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
0
arocioAuthor Commented:
Well, the point isn't like that, because the problem is that never it keeps the width the developer gives.
0
DrDelphiCommented:
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!!


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.