Solved

MSFLEXGRID CONTROL.  WORDWRAP?

Posted on 1997-07-14
9
858 Views
Last Modified: 2012-06-27
MSFLEXGRID  QUESTION.
From: Tim Brockway   Email: BROCKWAYJT&AOL.COM    (860) 242-3947

(VB5 Win 95)

HOW DOES ONE DETERMINE THE HEIGHT OF A ROW NECESSARY TO SHOW ALL WRAPPED AROUND TEXT?

The MsFlexGrid allows a row  to wrap text around vertically if it won't fit in a cell horizontally. But the cell does not autosize vertically to display the lower portion of the wrapped text.  The user has to size the rows height to show all the wrapped text. After assigning the text to the cell the rowheight property remains the same

How can one know the necessary row height?.

All suggestions gratefully received.
MSFLEXGRID  QUESTION.
From: Tim Brockway   Email: BROCKWAYJT&AOL.COM    (860) 242-3947

(VB5 Win 95)

HOW DOES ONE DETERMINE THE HEIGHT OF A ROW NECESSARY TO SHOW ALL WRAPPED AROUND TEXT?

The MsFlexGrid allows a row  to wrap text around vertically if it won't fit in a cell horizontally. But the cell does not autosize vertically to display the lower portion of the wrapped text.  The user has to size the rows height to show all the wrapped text. After assigning the text to the cell the rowheight property remains the same

How can one know the necessary row height?.

All suggestions gratefully received.
0
Comment
Question by:brockway
9 Comments
 
LVL 2

Expert Comment

by:msiman
Comment Utility
well, i have an idea,
tell me what u think:
divide the length of the data, by
the width of a cell (no. of chars)
this gives u the no. of lines.
set the height propert to the no. of lines
multiple by the height of each line
e.g.
if u have a cell at a width of 8 chars. the height of
each char is 240 points (in vb) and u have a
text of 20 chars (incl. spaces)
then do the following:
20/8= 2.5 -> int(2.5)=3
3*240=720.
in order to show 3 lines, which are the no. of lines
needed, set the height property to 720...
hope i understood your question
0
 

Author Comment

by:brockway
Comment Utility
Sorry, I know this "calculating" idea seems plausible but it breaks down in practice owing to the details.

For example we are dealing with word wrap which functions in entire words or hyphenated words. Thus a character by character count does not give the column width capacity. Other complications such as centering etc put the problem beyond the scope of a calculated solution of the kind you recommend. (Unless I want to spend years on it!).

Thanks for the idea.

I have also tried the following.

Use a dummy invisible label object (which  word wraps and DOES autosize vertically). By making the dummy label the same size as the grid cell then assigning the text to the label and seeing what it's height becomes. Then use that height for the row. This trick works great most of the time but when the col width gets narrow (less than say 2 inches) the label control autosizes its WIDTH as well as it's height. This is because if a single word or string gets large in a small label it autosizes width as well as height. My trick therefor does not work at these small sizes.

This lack of autosize  is a major flaw in MSFlexGrid. Any solution to this problem would be a boost to thousands of users.

Is there an API of some kind?

Thanks again msiman. Keep up the good work.

0
 
LVL 3

Expert Comment

by:ESI
Comment Utility
Use the .CellFontWidth property
When u change the font's width, its height remains the same, as specified with the CellFontSize property
You have the .CellWidth & .CellHeight properties to determine the exact size of the cell and use it to paste a TextBox control over the cell u need to edit, and after the user pressed the Enter key of the TextBox control lose the focus, recopy its contents to the cell and hide the text control. (Use the CellEnter event too)

0
 

Author Comment

by:brockway
Comment Utility
Thanks for the idea.

I should have explained more clearly that  I am using the cell for display only. There is no question of inputing text. The problem is knowing how high the row must be to display the wrapped text. There is no autosize property on the Flexgrid.

 Calculations based on Font size etc are out of the question since there are a thousand subtle problems when you start combining wordwrap and font changes. (Its difficult enough even if you stick to one font because you never know how wide a row will be in characters because of word wrap. Think about it).

But let us say I use the text box locked as an internal dummy to calculate the height. I'm not sure how that or an overlaid text box will give me the required height any better than a dummy autosizing label..

As I mentioned in a previous message I tried using the autosize facility of the label control with the inadequate outcome I described. An overlaid textbox would suffer the same shortcomings unless I'm missing something..

Thanks again for the idea.

We are going to solve this one somehow. I've got a feeling its an API

Keep those ideas rolling in and I'll test them out.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Expert Comment

by:ESI
Comment Utility
I beg the solution is in the GetSystemMetrics ?
0
 

Author Comment

by:brockway
Comment Utility
Sorry GetSystemMetrics does not pertain although I agree it sounds as if it should.

Thanks.

Keep the ideas coming.

Tim.
0
 
LVL 3

Expert Comment

by:ESI
Comment Utility
Good luck then ;-)
0
 
LVL 7

Accepted Solution

by:
tward earned 150 total points
Comment Utility
Below are the functions that I use.  I am using the regular Grid 1.0 but this should work for you also...  I also noticed that I have to wordwrap the text on my own..  I have a wordwrap function if you need that too....

Type TEXTMETRIC
        tmHeight As Long
        tmAscent As Long
        tmDescent As Long
        tmInternalLeading As Long
        tmExternalLeading As Long
        tmAveCharWidth As Long
        tmMaxCharWidth As Long
        tmWeight As Long
        tmOverhang As Long
        tmDigitizedAspectX As Long
        tmDigitizedAspectY As Long
        tmFirstChar As Byte
        tmLastChar As Byte
        tmDefaultChar As Byte
        tmBreakChar As Byte
        tmItalic As Byte
        tmUnderlined As Byte
        tmStruckOut As Byte
        tmPitchAndFamily As Byte
        tmCharSet As Byte
End Type

Public TextAttrib As TEXTMETRIC

Declare Function GetTextMetrics Lib "gdi32" Alias "GetTextMetricsA" (ByVal hdc As Long, lpMetrics As TEXTMETRIC) As Long

Private Sub Form1_Load()

  Call GetTextMetrics(Form1.hdc, TextAttrib)

End Sub

Public Sub UpDateGridSize(ByVal WhichGrid As Control, ByVal TextLength As Integer, ByVal ColumnNumber As Integer)
 
 Dim Counter As Integer
 Dim CRs As Integer
 Dim CRPosition As Integer
 
 CRs = 1
 CRPosition = 0
 
 If TextLength * TextAttrib.tmMaxCharWidth * Screen.TwipsPerPixelX > WhichGrid.ColWidth(ColumnNumber) Then
   
   WhichGrid.ColWidth(ColumnNumber) = TextLength * TextAttrib.tmMaxCharWidth * Screen.TwipsPerPixelX
     
 End If
 
 For Counter = 1 To TextLength 'Len(WhichGrid.Text)
 
    CRPosition = InStr(CRPosition + 1, WhichGrid.Text, Chr(13), 0)
    If CRPosition <> 0 Then
   
      CRs = CRs + 1
   
    Else
   
      Exit For
   
    End If
 
 Next Counter
 
 If WhichGrid.RowHeight(WhichGrid.Row) < TextAttrib.tmHeight * Screen.TwipsPerPixelY * CRs Then
   
   WhichGrid.RowHeight(WhichGrid.Row) = TextAttrib.tmHeight * Screen.TwipsPerPixelY * CRs
 
 End If

End Sub
0
 

Author Comment

by:brockway
Comment Utility
Thanks a million for the suggestion. I have done something similar and
I might take you up on the word wrap code if all else fails. If so I will give you all the points I have and even unto the seventh generation of my camels. For now I'm looking for a "non-calculating" answer.

But I'm simply astonished we have to get down to reinventing the wheel like this. It 1997 Microsoft !!! We did wordwrap 20 years ago. Where is the point of VB5 if we have to do this.?

Sorry to gripe.

But I really am  looking for a 'non-calculating" option. My dummy label trick works quite well so I'll stick with it for now.

Many thanks anyway.

Hope I can help you out sometime.

Tim..
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

763 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

13 Experts available now in Live!

Get 1:1 Help Now