Solved

MSFLEXGRID CONTROL.  WORDWRAP?

Posted on 1997-07-14
9
889 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
ID: 1428377
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
ID: 1428378
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
ID: 1428379
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:brockway
ID: 1428380
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
 
LVL 3

Expert Comment

by:ESI
ID: 1428381
I beg the solution is in the GetSystemMetrics ?
0
 

Author Comment

by:brockway
ID: 1428382
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
ID: 1428383
Good luck then ;-)
0
 
LVL 7

Accepted Solution

by:
tward earned 150 total points
ID: 1428384
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
ID: 1428385
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…

828 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