Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

msflexgrid col resize

Posted on 1999-07-12
3
Medium Priority
?
472 Views
Last Modified: 2013-12-25
How can i increase the size of a msflexgrid column to see the longest "string" completly and reduce the size if the column is too big compared to the longest "string"?
0
Comment
Question by:parduz
[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
3 Comments
 
LVL 10

Accepted Solution

by:
caraf_g earned 400 total points
ID: 1495256
I'm assuming it is possible to set the size of an msflexgrid and that you know how to do this.

1 Make sure the font of your msflexgrid is the same as the font on your form. If in doubt do
Set me.Font = YourFlexGrid.Font

2 Loop through all the cells in the column, I assume you know how to do this.

3 Dim dblWidth As Double
  dblWidth = 0
  'Loop through all the cells in the column:
       if me.TextWidth(<text in current cell>) > dblWidth Then
              dblWidth = me.TextWidth... (etcetera)
       End If
  'end of loop

Now you have the maximum text width in the cell.  
you may have to add a constant to take care of borders and a little bit of white space around the text so it looks nice. And finally, set the width of the column to this new size.

Good luck!!

0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1495257
Here's an example. Stick an msflexgrid on a new form and paste in the following code. See how it works...

Private Sub Form_Load()

Dim intRow As Integer
Dim intCol As Integer
Dim dblWidth As Double

With Me.MSFlexGrid1

    'Example: fills the grid with text, but puts something especially
    'large in the middle cell.
    'Let's try a grid with 3 rows and 3 columns
    .Cols = 3
    .FixedCols = 0
    .Rows = 3
    .FixedRows = 0
   
    For intRow = 0 To .Rows - 1
        For intCol = 0 To .Cols - 1
            .Row = intRow
            .Col = intCol
            .Text = "Blah blah blah " & CStr(intRow) & ":" & CStr(intCol)
            If .Row = 1 And .Col = 1 Then
                'put in something long to show how it works
                .Text = "lots & lots & lots of text, honest, guv!"
            End If
        Next
    Next
   
    'This is where the relevant bit starts:
    Set .Font = Me.Font
    For intCol = 0 To .Cols - 1
        dblWidth = 0
        For intRow = 0 To .Rows - 1
            .Row = intRow
            .Col = intCol
            If Me.TextWidth(.Text) > dblWidth Then
                dblWidth = Me.TextWidth(.Text)
            End If
        Next
        .ColWidth(intCol) = dblWidth + 120
    Next


End With


End Sub
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6821771
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects that and the expert will now receive these points, all verified.

Please click on your Member Profile, select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.
 
Thanks,
Moondancer
Moderator @ Experts Exchange
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

722 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