Solved

MSFlexGrid AUTO Rowheight and Colwidth

Posted on 2000-03-12
5
1,034 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 50 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

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