How do I set the column width to be = to the amount of text
(the text length varies)
How do I set the column width to be = to the amount of text
(the text length varies)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
Very good question.
Although I've never tried the way I'd approach is:
Check all Rows for Largest number of Characters
Use Length of that word to and then You need to
Figure out the Twips per Character.
I've only seen Twips Per Pixel so I'm not sure where to
go from here.
thats what im doing...
but ..the TextWidth() command isnt quite enough
it comes up with 1125 for one col where the column needs about 1400 to fit it...
hmmm...
thanks
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
nevermind..now that I removed the cellfontbold = true... it works
the bold was messing up the textwidth()
thanks
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
Here is a Generic routine I've put together a while back:
VB Code:
Public Sub ResizeGrid(pGrid As MSFlexGrid, pForm As Form) Dim intRow As Integer Dim intCol As Integer With pGrid For intCol = 0 To .Cols - 1 For intRow = 0 To .Rows - 1 If .ColWidth(intCol) < pForm.TextWidth(.TextMatrix(intRow, intCol)) + 100 Then .ColWidth(intCol) = pForm.TextWidth(.TextMatrix(intRow, intCol)) + 100 End If Next Next End With End Sub
Then just call this routine like this:
ResizeGrid MSFlexGrid1, Form1
similar to what I did..
But.. As I added each row...I checked...if the textwidth + 100 > current column width the make the colwidth = textwidth + 100
only problem is some of the cols have to be bold. Im working on a solution...
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
This seemed to work for me. Scrolling through every cell in that column, finding the max Twip size and then adjusting the cell for the max size:
Private Sub mnuAdjust_Click(Index As Integer)
Dim i As Integer
Dim maxTwips As Integer
Dim Twips As Integer
With Me.MSFlexGrid1
Me.ScaleMode = vbTwips
For i = 0 To .Rows - 1
Twips = Me.TextWidth(.TextMatrix(i, .ColSel))
If Twips > maxTwips Then
maxTwips = Twips
End If
Next i
.ColWidth(.ColSel) = maxTwips * Me.MSFlexGrid1.Font.Size / Me.Font.Size + 100 '* Screen.TwipsPerPixelX
End With
End Sub
Thanks for the help.
![]()
When using TextWidth, it uses the Font settings of the object - your form in this case. If you set your form's font settings to the same as the font settings of the col you are trying set the width on, you'll get the right numbers.Originally posted by geoff_xrx
similar to what I did..
But.. As I added each row...I checked...if the textwidth + 100 > current column width the make the colwidth = textwidth + 100
only problem is some of the cols have to be bold. Im working on a solution...
TG
* I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.-I also subscribe to all threads I participate, so there's no need to pm when there's an update.*
*Proof positive that searching the forums does work: View Thread *
* How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
* How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *
* Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
"There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN