Board index » delphi » Delphi DBGrid Column widths

Delphi DBGrid Column widths

Hi all,

Has anyone found a way to set the column width of a DBGrid component at
run time?  I have scanned all the FAQ files I could lay my hands on, but
it hasnt helped.

Any help would be appreciated.

Regards

Robert

rpal...@mail.dcscomp.com.au

 

Re:Delphi DBGrid Column widths


Quote
Robert Pallot <rpal...@mail.dcscomp.com.au> wrote:
>Hi all,
>Has anyone found a way to set the column width of a DBGrid component at
>run time?  I have scanned all the FAQ files I could lay my hands on, but
>it hasnt helped.
>Any help would be appreciated.

This should do it.

DBGrid.Columns[0].Width := ???;

______________________________________
Scott Martin - smar...@firstnethou.com

Re:Delphi DBGrid Column widths


In <3178D3D7.3...@mail.dcscomp.com.au> Robert Pallot

Quote
<rpal...@mail.dcscomp.com.au> writes:

>Hi all,

>Has anyone found a way to set the column width of a DBGrid component
at
>run time?  I have scanned all the FAQ files I could lay my hands on,
but
>it hasnt helped.

>Any help would be appreciated.

>Regards

>Robert

>rpal...@mail.dcscomp.com.au

You can do it thru the object inspector on the tField level.
Infopower's grid lets you do it right there.

Ben
Arrow

Re:Delphi DBGrid Column widths


Quote
> >Hi all,

> >Has anyone found a way to set the column width of a DBGrid component
> at
> >run time?  I have scanned all the FAQ files I could lay my hands on,I have the same problem.  I have tried to use the DisplayWidth property

of the Fields as follows:

SeeOrdersGrid.Fields[0].DisplayWidth := 11

The problem is, when I run the program, I get a GPF at that point.  
However, I can continue to run and the grid shows up OK, only with the
width unchanged.

What am I doing wrong?

Thanks,
Dan

Re:Delphi DBGrid Column widths


Quote
Dan Axtell <daxt...@connix.com> wrote:
>> >Hi all,

>> >Has anyone found a way to set the column width of a DBGrid component
>> at
>> >run time?  I have scanned all the FAQ files I could lay my hands on,I have the same problem.  I have tried to use the DisplayWidth property
>of the Fields as follows:
>SeeOrdersGrid.Fields[0].DisplayWidth := 11

A few Changes:

DBGrid.Columns[0].Width := ???;

Quote
>The problem is, when I run the program, I get a GPF at that point.  
>However, I can continue to run and the grid shows up OK, only with the
>width unchanged.
>What am I doing wrong?
>Thanks,
>Dan

______________________________________
Scott Martin - smar...@firstnethou.com

Re:Delphi DBGrid Column widths


Quote
Dan Axtell wrote:

> > >Hi all,

> > >Has anyone found a way to set the column width of a DBGrid component
> > at
> > >run time?  I have scanned all the FAQ files I could lay my hands on,I have the same problem.  I have tried to use the DisplayWidth property
> of the Fields as follows:

> SeeOrdersGrid.Fields[0].DisplayWidth := 11

> The problem is, when I run the program, I get a GPF at that point.
> However, I can continue to run and the grid shows up OK, only with the
> width unchanged.

> What am I doing wrong?

> Thanks,
> Dan

An alternate way, if you know the sizes you want and they're not going to change,
is to typecast the DBGrid to a TStringGrid...

TStringGrid(MyDBGrid).ColWidths[0] := 50;
TStringGrid(MyDBGrid).ColWidths[1] := 120;

Like that.

Re:Delphi DBGrid Column widths


In <3178D3D7.3...@mail.dcscomp.com.au> Robert Pallot

Quote
<rpal...@mail.dcscomp.com.au> writes:

>Hi all,

>Has anyone found a way to set the column width of a DBGrid component
at
>run time?  I have scanned all the FAQ files I could lay my hands on,
but
>it hasnt helped.

>Any help would be appreciated.

>Regards

>Robert

>rpal...@mail.dcscomp.com.au

procedure TMyGrid.Create(Aowner: TComponent);
begin
 .
 .
 .
  ColWidths[i] := newwidth;  

Where i is the column (zero based) you wish to resize.
DefaultColWidth sets them all unless overridden by ColWidths.

Bill Touchstone
ycc...@gate.net

Re:Delphi DBGrid Column widths


By Jove, Watson!  There is clear evidence that Bill Touchstone said:
* In <3178D3D7.3...@mail.dcscomp.com.au> Robert Pallot
* >Has anyone found a way to set the column width of a DBGrid component
* at
* >run time?  I have scanned all the FAQ files I could lay my hands on,
* but
* >it hasnt helped.
* procedure TMyGrid.Create(Aowner: TComponent);
* begin
*  .
*   ColWidths[i] := newwidth;  
*
* Where i is the column (zero based) you wish to resize.
* DefaultColWidth sets them all unless overridden by ColWidths.

Oh, Bill!  Ten out of ten for trying, only.  Unfortunately, ColWidths[] and
DefaultColWidth aren't supported for TDBGrid.  Instead, you set one of the
properties of the TField objects attached to the items in the table that's
being displayed.  I think it's DisplayWidth.  You'll need to double click
the associated TTable or TQuery object, use F11 to set field defs once
you've added the right ones to the list, and Robert's your mother's brother!
[Sorry, Australian colloquialism: "Bob's your uncle" means "and there you
go, it works"]

: Eric :
--
Emperor:  What do you think, Court Composer?              |     Paul Sleigh
Salieri:  Italians are quite fond of waxworks, Majesty.   |  Eric the Fruitbat
          Our religion is largely based upon them.        |  fruitbat@canberra
                                            - _Amadeus_   |    .DIALix.oz.au

Other Threads