Make dbgrid columns width follow form width ??? 
Author Message
 Make dbgrid columns width follow form width ???

Hi !

Can anyone help me out here......

I want the columns in a dbgrid follow the width in the form,
if changing size width the columns should change so it
fits the form...

Tnx

Bj?rn



Sun, 10 Dec 2000 03:00:00 GMT  
 Make dbgrid columns width follow form width ???

You have to write down your own code.
In the Form_Resize event you have to recalculate the dimension of the
control
due to the change of the form size. Then you have to resize each column.

To work with the following example open a new project. On Form1 draw a
Dbgrid.
Set the Align property of Dbgrid1 to 1 (Align Top). Copy and paste the
following
code to the general declaration section of from1. And run.

Private Sub Form_Resize()
    DBGrid1.Height = Height - 400
   For Each Column In DBGrid1.Columns
        Column.Width = (DBGrid1.Width - 330) \ DBGrid1.Columns.Count
    Next Column
End Sub

Note that this example assumes each column has the same width as others.

Youll' ask why Height -400 and Dbgrid1.Width -330. Right ?
Well 400 is approximately the heigth of the caption bar of the window.
And 330 is approximately the width of the record selectors column in
dbgrid1.

Hope this helps to solve your problem.

Bye

Bj?rn J?nsson ha scritto:

Quote:
> Hi !

> Can anyone help me out here......

> I want the columns in a dbgrid follow the width in the form,
> if changing size width the columns should change so it
> fits the form...

> Tnx

> Bj?rn

  vcard.vcf
< 1K Download


Sun, 10 Dec 2000 03:00:00 GMT  
 Make dbgrid columns width follow form width ???

Quote:
>    DBGrid1.Height = Height - 400

This should be
   DBGrid1.Height = Me.ScaleHeight

Regards,
Simon Jones
PC Pro Magazine



Sun, 10 Dec 2000 03:00:00 GMT  
 Make dbgrid columns width follow form width ???

In the Form_Resize event you should run through the grid columns and change
their widths.
I usually work out what fraction of the total width each column is and then
expand/contract them so that they take up 100% of the space but in the same
proportions. Don't forget to leave room for the row header and the vertical
scroll bar (if they are visible).

Regards,
Simon Jones
PC Pro Magazine



Sun, 10 Dec 2000 03:00:00 GMT  
 Make dbgrid columns width follow form width ???

Quote:

> Hi !

> Can anyone help me out here......

> I want the columns in a dbgrid follow the width in the form,
> if changing size width the columns should change so it
> fits the form...

> Tnx

> Bj?rn

This makes all columns in Grd the same width.  It;s easily modified to
create different widths for each column.

Sub Form_ReSize

Grd.width = Form1.Width - (some factor, maybe 200-500 twips)

For i=1 to (the number of columns in Grd)
    Grd.Columns(i-1).width = Grd.Width / (the number of columns in Grd)
Next

End Sub

--
_________________________________________________________________

C. Stone



Vacuum Technology Incorporated
1003 Alvin Weinberg Drive
Oak Ridge, TN 37830

Ph# (423)481-3342
Fx# (423)481-3788
_________________________________________________________________



Mon, 11 Dec 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Setting datagrid column width sets width of toplevel!!

2. Set Grid width to sum of Column Widths

3. ListView column width = ListView width ?

4. Total width of columns = Width of ListView

5. Total width of columns = Width of ListView

6. Total width of columns = Width of ListView

7. Total width of columns = Width of ListView

8. Making a column width equal 0

9. Setting form width/height = image width/height

10. How to resize the column width in DBGrid?

11. DBGrid control and column widths

12. HELP :Setting Column width in a DBGrid ?

 

 
Powered by phpBB® Forum Software