Solved

MSFlexGrid AUTO Rowheight and Colwidth

Posted on 2000-03-12
5
1,043 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
[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
  • 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
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…
Suggested Courses
Course of the Month10 days, 2 hours left to enroll

624 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