[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

DBGrid Column Width

Posted on 1998-04-28
8
Medium Priority
?
425 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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

650 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