Solved

DBGrid Column Width

Posted on 1998-04-28
8
415 Views
Last Modified: 2010-05-18
How do you set the Columns Collection width property to display 50 charecters of data (or any number of charecters)?  I told a look at the width property of one of my columns and it is in the form of "xxxx.xxx".  What does this mean? I do not want to upgrade to TDBGrid.
0
Comment
Question by:baileys
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:stevesm
ID: 1433318
Baileys,

Try this code on a 4 column grid with 2 rows on the load.
Alter the code below to suit your needs

Private Sub Form_Load()

'Configure the grid by setting the columns,
'captions,widths and alignments
    grdYourGrid.Row = 0
'Set the properties for the first column
    grdYourGrid.Col = 0
    grdYourGrid.Text = "Column 1"
    grdYourGrid.ColWidth(0) = 600
    grdYourGrid.FixedAlignment(0) = vbCenter
'Set the properties for the second column
    grdYourGrid.Col = 1
    grdYourGrid.Text = "Column 2"
    grdYourGrid.ColWidth(1) = 1900
    grdYourGrid.ColAlignment(1) = vbLeftJustify
'Set the properties for the third column
    grdYourGrid.Col = 2
    grdYourGrid.Text = "Column 3"
    grdYourGrid.ColWidth(2) = 800
    grdYourGrid.ColAlignment(2) = vbCenter
'Set the properties for the fourth column
    grdYourGrid.Col = 3
    grdYourGrid.Text = "Column 4"
    grdYourGrid.ColWidth(3) = 1600
    grdYourGrid.ColAlignment(3) = vbLeftJustify
End Sub


Let me know if you need any more info by rejecting my answer and commenting back.

Good luck.....Steve

0
 

Author Comment

by:baileys
ID: 1433319
Got an error.  COLWIDTH was not a method of DBGrid.

                Sheila
0
 

Expert Comment

by:mattyboy
ID: 1433320
Just a side note....

Setting the width of a column sets it in pixels, not in characters.  So, to find out how wide 50 characters is:

Create a Label on your Form, and make it invisible.  Set it's AutoSize property to True.  Change the Caption of the Label to the text you are going to display in your column.  Then, set the width of the column to the width of the Label.

mattyboy
0
 

Expert Comment

by:mattyboy
ID: 1433321
ooops
twips, not pixels!

mattyboy
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Expert Comment

by:stevesm
ID: 1433322
Sheila,

I was wrong the code is for a flex grid not a dbgrid.

The property setting is in the property pages for the dbgrid on the tab marked layout where it has a label marked "width". You right click on the control for the pop up menu.

Let me know if this works....Steve
0
 
LVL 6

Accepted Solution

by:
clifABB earned 100 total points
ID: 1433323
If you can make the form have the same font as the grid, use this code:

'To make column 1 50 characters wide
DBGrid1.Columns(1).Width = Form1.TextWidth(String(50,"X"))

Remember that different fonts have different widths and there are some fonts where each character has a different with.  This font you're reading is a good example, the "I" is much narrower than a "W".  Using an "X" in this case is a good median value.
0
 

Author Comment

by:baileys
ID: 1433324
That solved the problem perfectly. I have been trying to solve this problem off and on for the last 3 weeks.  Thanks!!

                        Sheila
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1433325
You're quite welcome.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 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

17 Experts available now in Live!

Get 1:1 Help Now