Results 1 to 3 of 3

Thread: Flexgrid and Wordwrap - how do you know it has happened?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Flexgrid and Wordwrap - how do you know it has happened?

    I have a FlexGrid with WordWrap set to True. It is populated from a recordset. Some of the fields contain a lot of text. Some contain just a few words.

    I have Wordwrap = True but, as far as I can make out, if words in a cell wrap, I have to manually set the height of the row (have to say, can't believe how primitive this is!).

    So, how can you detect whether words in a particular cell have wrapped and, if you can detect that:

    how do you know how many times wordwrap has happened in any cell?
    i.e. how many lines of text there are in any cell

    how do you determine how high to make the row based on the number of lines of text?

    Cheers

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Flexgrid and Wordwrap - how do you know it has happened?

    With the flexgrid, setting wordwrap to true does wrap the text, but the
    problem is that the rowheight doesn't change.

    Suggestion: Place an invisible textbox on your form and use it with the following code.

    VB Code:
    1. Public Sub ReSizeCellHeight(MyRow As Long, MyCol As Long)
    2. Dim LinesOfText As Long
    3. Dim HeightOfLine As Long
    4.  
    5. 'Set MSFlexGrid to appropriate Cell
    6. OrderGrid.Row = MyRow
    7. OrderGrid.Col = MyCol
    8.  
    9. 'Set textbox width to match current width of selected cell
    10. txtAdjuster.Width = OrderGrid.ColWidth(MyCol)
    11.  
    12. 'Set font info of textbox to match FlexGrid control
    13. txtAdjuster.Font.Name = OrderGrid.Font.Name
    14. txtAdjuster.Font.Size = OrderGrid.Font.Size
    15. txtAdjuster.Font.Bold = OrderGrid.Font.Bold
    16. txtAdjuster.Font.Italic = OrderGrid.Font.Italic
    17. txtAdjuster.Font.Strikethrough = OrderGrid.Font.Strikethrough
    18. txtAdjuster.Font.Underline = OrderGrid.Font.Underline
    19.  
    20. 'Set font info of form to match FlexGrid control
    21. Me.Font.Name = MSFlexGrid1.Font.Name
    22. Me.Font.Size = MSFlexGrid1.Font.Size
    23. Me.Font.Bold = MSFlexGrid1.Font.Bold
    24. Me.Font.Italic = MSFlexGrid1.Font.Italic
    25. Me.Font.Strikethrough = MSFlexGrid1.Font.Strikethrough
    26. Me.Font.Underline = MSFlexGrid1.Font.Underline
    27.  
    28. 'Put the text from the selected cell into the textbox
    29. txtAdjuster.Text = Trim$(OrderGrid.Text)
    30.  
    31. 'Get the height of the text in the textbox
    32. HeightOfLine = Me.TextHeight(txtAdjuster.Text)
    33.  
    34. 'Call API to determine how many lines of text are in text box
    35. LinesOfText = SendMessage(txtAdjuster.hwnd, EM_GETLINECOUNT, 0&, 0&)
    36.  
    37. 'Check to see if row is not tall enough
    38. If OrderGrid.RowHeight(MyRow) < (LinesOfText * HeightOfLine) Then
    39. 'Adjust the RowHeight based on the number of lines in textbox
    40. OrderGrid.RowHeight(MyRow) = (LinesOfText) * HeightOfLine
    41. End If
    42. End Sub

    Hope this helps...
    ps: not my code. picked up from a website...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    589

    Re: Flexgrid and Wordwrap - how do you know it has happened?

    Thanks very much for that - managed to get it working.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width