?
Solved

MSFlexGrid Dynamically Autosize row height

Posted on 2005-02-24
5
Medium Priority
?
1,516 Views
Last Modified: 2012-08-13
Hi,
I populate the MSflexGrid from database table it contains Col1 Date Col2 Note (memo Field )
The memo field that contains a large amount of text and need to be able to read it all.
Some rows  display 100% and some less depends on the size of the field.
I need that they all will be displayed correctly and allow the user to easily read all the note
So My question is How to dynamically resize the row height to match the memo field.
Thanks
0
Comment
Question by:mayajhon1
[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
  • 2
5 Comments
 
LVL 7

Expert Comment

by:Smallint
ID: 13395656
0
 

Author Comment

by:mayajhon1
ID: 13395954
Thanks  Smallint for your reply,
But this link is about how to Make a FlexGrid's columns fit its data
I'm thinking more about how to Make a FlexGrid's Rows fit its data
I want to adjust the height not the width.
Thanks
Maya
0
 
LVL 18

Expert Comment

by:Sethi
ID: 13399227
0
 
LVL 7

Accepted Solution

by:
Smallint earned 1000 total points
ID: 13401670
Give it a shot.

Code assumes:

* WordWrap property of Flexgrid is enabled.
* Font used is flexgrid is the same than form where is placed

This code will not work when column width is very little because flexgrid begins to show strange behaviour.

Cheers


Private Function FindTextHeight(flx As MSFlexGrid, r As Long, C As Long) As Long
    Dim text_Height As Long
    Dim cell_width As Long
    Dim n As Long
   
    Dim lNextBlank As Long
    Dim lCurrentBlank As Long
    Dim lLastBlank As Long
   
    'A little bit higher due to spacing between lines
    FindTextHeight = TextHeight(" ") * 1.2
   
    text_Height = FindTextHeight
   
    lCurrentBlank = 1
    n = lCurrentBlank
   
    While n < Len(flx.TextMatrix(r, C))
   
         lNextBlank = InStr(n, flx.TextMatrix(r, C), " ")
         
         If lNextBlank > 0 Then
         
            If TextWidth(Mid(flx.TextMatrix(r, C), lCurrentBlank, lNextBlank - lCurrentBlank)) > flx.ColWidth(C) Then
                FindTextHeight = FindTextHeight + text_Height
                If lCurrentBlank <> 1 Then
                    lCurrentBlank = lLastBlank + 1
                Else
                    lCurrentBlank = lNextBlank + 1
                End If
               
                lLastBlank = lNextBlank
                n = lNextBlank + 1
            Else
                lLastBlank = lNextBlank
                n = lNextBlank + 1
            End If
        Else
            FindTextHeight = FindTextHeight + text_Height
            n = Len(flx.TextMatrix(r, C))
        End If
         
    Wend
   

End Function

Private Sub AutoFitFlexGridHeight(ByVal flx As MSFlexGrid)
Dim r As Long
Dim C As Long
Dim cell_Height As Single
Dim row_Height As Single

    For r = 0 To flx.Rows - 1
        row_Height = 0
        For C = 0 To flx.Cols - 1
            cell_Height = FindTextHeight(flx, r, C)
            If row_Height < cell_Height Then row_Height = cell_Height
        Next
        flx.RowHeight(r) = row_Height
    Next
End Sub

0
 

Author Comment

by:mayajhon1
ID: 13403499
Thanks Sethi but the code didn't work but I appreciate the help.
Thank you Smallint the code worked and the key point for me was that the font was too big as soon as I reduced it it worked!
Thank you,
Maya
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
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 …
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 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…
Suggested Courses
Course of the Month7 days, 20 hours left to enroll

765 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