Solved

Sizing Columns of a dbgrid at runtime

Posted on 2006-11-27
5
220 Views
Last Modified: 2010-04-05
hi everybody
i am facing a problem with dbgrids.
i am using a single grid for displaying data of different tables. each table is having different number of fields.
so when assinging the query to the grid at runtime ... in some tables where number of fields is less empty space is left at the right of the grid .. and when the number of fields are more a horizontal scrollbar appears on the grid.
i want my form size to remain the same.
i hope the question is understood.

thanks in advance
0
Comment
Question by:Asmitagoyal
5 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 18025839
>i hope the question is understood.
not really, what is wrong with the scrollbar and the free space(if there are less columns)?
thats a kind of dynamic, which keeps your form in the current metrics

nevertheless you can adjust the column-width like (preferable in the afteropen-event of your dataset)

  dbgrid1.Columns[index].Width := ...

meikl ;-)

0
 

Author Comment

by:Asmitagoyal
ID: 18025894
hello
using dbgrid1.Columns[index].Width := ... is a cumbersome task
i've to know the width of all the fields in advance ... which is not possible.
i don't want neither the extra free space nor the scroll bar .
if there is any other method for this ...... kindly suggest
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 18025906
>if there is any other method for this
no, not as i know ->
you have to calculate the width byself depending on count of fields and type of field

meikl ;-)
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 18025940
>using dbgrid1.Columns[index].Width := ... is a cumbersome task
>i've to know the width of all the fields in advance ... which is not possible.

cumbersome??? Asmita, if you think this way, there is NO way.

You don't need to know the width of all fields. You can write a generic routine which can work for all tables. Let me know if you need more help on this.
0
 
LVL 11

Accepted Solution

by:
calinutz earned 500 total points
ID: 18026164
A solution to your problem can be found here:
But there is a lot of work to do left...

http://delphi.about.com/od/usedbvcl/l/aa050404a.htm


regards
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now