[Webinar] Streamline your web hosting managementRegister Today


msflexgrid col resize

Posted on 1999-07-12
Medium Priority
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"?
Question by:parduz
  • 2
LVL 10

Accepted Solution

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!!

LVL 10

Expert Comment

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
    '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
        .ColWidth(intCol) = dblWidth + 120

End With

End Sub

Expert Comment

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.
Moderator @ Experts Exchange

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

591 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