• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 858
  • Last Modified:

Autosizing a column in msflexgrid

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
1 Solution
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now