?
Solved

Autosizing a column in msflexgrid

Posted on 2004-10-20
2
Medium Priority
?
853 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
[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 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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

770 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