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
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...
Re: Flexgrid and Wordwrap - how do you know it has happened?
Thanks very much for that - managed to get it working.