[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

DBGrid Column Width

Posted on 1998-04-28
8
Medium Priority
?
427 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

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

mattyboy
0
 
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 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

873 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