Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSFlexGrid: Wrap the text by resizing row height or column width?

Status
Not open for further replies.

mingichu

MIS
Apr 12, 2002
29
US
Hi! All experts,

I am working on MsFlexGrid in VB6.
I'd like to resize row height or column width if the data length can't fit into the cell. I tried to set WordWrap as True in the object property or dynamically in the procedure. Neither can't work.
I would appreciate if anyone can help me solve it. Thanks in advance!!
 
You are correct that you need to set the .WordWrap property to True. But you must also set the .RowHeight(<Row Num>) also to match.

The following snippet of code sets the row height for every row in the flexgrid to the appropriate height. It assumes that the Font settings in the grid are the same as the default Font settings for the form. It gets a little more complicated if the font settings change within the grid, but I hope that this at least will get you started.

prth = Me.TextHeight(&quot;A&quot;)
grdTable.WordWrap = True
For RowID = 0 To grdTable.Rows - 1
maxh = 0
For ColID = 0 To grdTable.Cols - 1
colw = grdTable.ColWidth(lInt_ColID)
If (colw < 0) Then ' -1 is the default width
colw = 1000
End If
prtw = Me.TextWidth(grdTable.TextMatrix(RowID, ColID))
nrow = Int(prtw / colw) + 1
maxh = IIf((nrow > maxh), nrow, maxh)
Next ColID
If (maxh > 1) Then
grdTable.RowHeight(RowID) = maxh * prth
End If
Next RowID
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top