Solved

MSFlexGrid AUTO Rowheight and Colwidth

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now