MSFLEXGRID CONTROL. WORDWRAP?

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.
brockwayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

msimanCommented:
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
brockwayAuthor Commented:
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
ESICommented:
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

brockwayAuthor Commented:
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
ESICommented:
I beg the solution is in the GetSystemMetrics ?
0
brockwayAuthor Commented:
Sorry GetSystemMetrics does not pertain although I agree it sounds as if it should.

Thanks.

Keep the ideas coming.

Tim.
0
ESICommented:
Good luck then ;-)
0
twardCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brockwayAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.