changing the width columns

Posted on 2000-02-04
Medium Priority
Last Modified: 2010-04-04
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

                  Do you know anything about it ??
Question by:arocio

Expert Comment

ID: 2490584
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

Expert Comment

ID: 2490596
Is the width of the column header/title, less than the width he is setting the column to?

Accepted Solution

DrDelphi earned 100 total points
ID: 2490826
Try this out.. it's sneaky, but it does the job:

var colwidth:integer;

Good luck!!
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 27

Expert Comment

ID: 2490911
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.


Author Comment

ID: 2501564
Well, the point isn't like that, because the problem is that never it keeps the width the developer gives.

Expert Comment

ID: 2501804
I will ammend my answer to suit :

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

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

Good luck!!


Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question