Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8802585
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:07:23+00:00 2026-06-14T01:07:23+00:00

I am trying to make a frame with a DBGrid that will serve for

  • 0

I am trying to make a frame with a DBGrid that will serve for more than 10 tables with half of its fields as defaults, and other fields exclusive for each table.

As the space for the columns are limited and I do not want to configure each column of each table manually because it is very poor quality work, I was wondering a way to calculate the width of each column by the largest content of a row inside that column, measured by the own component or by the data set.

Does anyone knows the way? Is there out in the world some custom component with that power?
I need a solution that implements increase and decrease of size, according to the the visible data in the all visible columns of the grid.
My solution so far had a problem with the painting of the selected cell, witch jumps out of the selected dataset row.

enter image description here


Note: Please, do not close my question. It is not about the fit with the grid’s width or the form’s width. It is about all the columns width to minimize the horizontal scrollbar, but not necessarily hide it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T01:07:25+00:00Added an answer on June 14, 2026 at 1:07 am

    What you have to do is to use the grid’s canvas to measure the contents of each column and set the column’s width accordingly. You can either iterate through the dataset or use the OnColumnDraw-Event to adjust the width on the fly.

    Here’s a sample (I had to use an offset of 5 pixels)

    procedure TForm7.DBGridDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    Var
      w : Integer;
    
    begin
      w := 5+DBGrid.Canvas.TextExtent(Column.Field.DisplayText).cx;
      if w>column.Width then Column.Width := w;
    end;
    
    procedure TForm7.FormActivate(Sender: TObject);
    Var
      i : Integer;
    
    begin
      // Initialize width
      for I := 0 to DBGrid.Columns.Count - 1 do
        DBGrid.Columns[i].Width := 5 + DBGrid.Canvas.TextWidth(DBGrid.Columns[i].title.caption)
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a nice frame for a logo that will be inserted
I am trying to make a frame from code so that I can apply
I'm trying to make a decision tree using rpart using a data frame that
I'm trying make an entity with doctrine that has three associations with other entities
I am trying to make a simple program that will subtract an object from
I'm trying to make a HTML page (lets say index.html) that will have a
I am trying to make a function that will determine if value in a
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I am trying to make a little ball that rolls around based on the
I am trying to make a ScrolledWindow that can scroll over a grid of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.