Solved

Autosizing a column in msflexgrid

Posted on 2004-10-20
2
847 Views
Last Modified: 2008-02-01
Is it possible to autosize a column in  the msflexgrid countrol ?
I'm loading text into the grid and would like to resize a particular column in the grid, so the user can see all the data.
(I know I can allow the user to resize the column.)
but I'd like to do it automatically.
Any help appreciated
Paul
0
Comment
Question by:skintpaul
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 50 total points
ID: 12356929
0
 
LVL 11

Expert Comment

by:dbrckovi
ID: 12356961
Try this:
 - paste this on the form where is your flexgrid
 - add command button to see how to use it
'---------------------------------------------------------------------
Sub AutoSize(FlexGrid As MSFlexGrid, Column As Integer)
    Dim LongestEntry As Integer
    Dim X As Integer
   
   
    If Column >= FlexGrid.Cols Then
        MsgBox "Column " & Column & " does not exist!"
        Exit Sub
    End If
   
    For X = 0 To FlexGrid.Rows - 1
        If TextWidth(FlexGrid.TextMatrix(X, Column)) > LongestEntry Then LongestEntry = TextWidth(FlexGrid.TextMatrix(X, Column))
    Next X
   
    If LongestEntry < 400 Then LongestEntry = 400
    FlexGrid.ColWidth(Column) = LongestEntry * 1.1
End Sub

Private Sub Command1_Click()
    AutoSize MSFlexGrid1, 2
End Sub
'-------------------------------------------------------------------
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Window placement 17 65
VBA color chart bars 12 67
Sending a email via excel using vba 6 58
Modifying Conditional Format from VBA code 3 33
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now