Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MSFlexGrid AUTO Rowheight and Colwidth

Posted on 2000-03-12
5
Medium Priority
?
1,060 Views
Last Modified: 2008-03-17
Is there someone who know how to auto set the control's column width and row height after one have populated it with data. If possible, a module PLSE
0
Comment
Question by:beneke
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:mcrider
ID: 2611275
There is no way to autoset the column width and height, BUT, you can do something like this... This makes sure the column width is wide enough for the text...

Dim lWidth As Long

MSFlexGrid1.Row = 1
MSFlexGrid1.Col = 1
MSFlexGrid1.Text = "This is a test of the emergency broadcast system"
Form1.FontName = MSFlexGrid1.CellFontName
Form1.FontSize = MSFlexGrid1.CellFontSize
Form1.FontBold = MSFlexGrid1.CellFontBold
lWidth = Form1.TextWidth(MSFlexGrid1.Text) + 120
If MSFlexGrid1.ColWidth(MSFlexGrid1.Col) < lWidth Then
    MSFlexGrid1.ColWidth(MSFlexGrid1.Col) = lWidth
End If



Cheers!®©
0
 

Author Comment

by:beneke
ID: 2611427
Hi MCRIDER

Your code work fine for the width, no idea how to set the height? My problem is that some of the rows might have newline characters and I want to display these rows.

PS. If I don't get anything extraordinary I will reward you!
0
 
LVL 14

Accepted Solution

by:
mcrider earned 200 total points
ID: 2611933
Here you go... This does both height and width.  Width gets set with the width of the longest line in multiple line text...


    Dim lWidth As Long
    Dim lHeight As Long
    Dim iVal As Long
    Dim jVal As Long
    Dim lBuf As String
   
    With MSFlexGrid1
        .Row = 1
        .Col = 1
        Form1.FontName = .CellFontName
        Form1.FontSize = .CellFontSize
        Form1.FontBold = .CellFontBold
        .Text = "This is a test of the" + vbCrLf + "emergency broadcast system" + vbCrLf + "This is only a test"
        iVal = 1
        Do
            jVal = InStr(iVal, .Text, vbCrLf)
            If jVal = 0 Then
                lBuf = Mid$(.Text, iVal)
                If lWidth < Form1.TextWidth(lBuf) + 120 Then
                    lWidth = Form1.TextWidth(lBuf) + 120
                End If
                Exit Do
            End If
            lBuf = Mid$(.Text, iVal, jVal - iVal)
            If lWidth < Form1.TextWidth(lBuf) + 120 Then
                lWidth = Form1.TextWidth(lBuf) + 120
            End If
            iVal = jVal + 2
        Loop
        If .ColWidth(.Col) < lWidth Then
            .ColWidth(.Col) = lWidth
        End If
        lHeight = Form1.TextHeight(.Text) + 120
        If .RowHeight(.Row) < lHeight Then
            .RowHeight(.Row) = lHeight
        End If
    End With




Cheers!®©
0
 

Author Comment

by:beneke
ID: 2612333
GREAT!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2612533
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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

824 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