|
-
Jan 10th, 2007, 12:20 PM
#1
Thread Starter
Fanatic Member
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
-
Jan 10th, 2007, 05:08 PM
#2
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:
Public Sub ReSizeCellHeight(MyRow As Long, MyCol As Long)
Dim LinesOfText As Long
Dim HeightOfLine As Long
'Set MSFlexGrid to appropriate Cell
OrderGrid.Row = MyRow
OrderGrid.Col = MyCol
'Set textbox width to match current width of selected cell
txtAdjuster.Width = OrderGrid.ColWidth(MyCol)
'Set font info of textbox to match FlexGrid control
txtAdjuster.Font.Name = OrderGrid.Font.Name
txtAdjuster.Font.Size = OrderGrid.Font.Size
txtAdjuster.Font.Bold = OrderGrid.Font.Bold
txtAdjuster.Font.Italic = OrderGrid.Font.Italic
txtAdjuster.Font.Strikethrough = OrderGrid.Font.Strikethrough
txtAdjuster.Font.Underline = OrderGrid.Font.Underline
'Set font info of form to match FlexGrid control
Me.Font.Name = MSFlexGrid1.Font.Name
Me.Font.Size = MSFlexGrid1.Font.Size
Me.Font.Bold = MSFlexGrid1.Font.Bold
Me.Font.Italic = MSFlexGrid1.Font.Italic
Me.Font.Strikethrough = MSFlexGrid1.Font.Strikethrough
Me.Font.Underline = MSFlexGrid1.Font.Underline
'Put the text from the selected cell into the textbox
txtAdjuster.Text = Trim$(OrderGrid.Text)
'Get the height of the text in the textbox
HeightOfLine = Me.TextHeight(txtAdjuster.Text)
'Call API to determine how many lines of text are in text box
LinesOfText = SendMessage(txtAdjuster.hwnd, EM_GETLINECOUNT, 0&, 0&)
'Check to see if row is not tall enough
If OrderGrid.RowHeight(MyRow) < (LinesOfText * HeightOfLine) Then
'Adjust the RowHeight based on the number of lines in textbox
OrderGrid.RowHeight(MyRow) = (LinesOfText) * HeightOfLine
End If
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
-
Jan 11th, 2007, 03:55 AM
#3
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|