MSFlexgrid - Set column width to text width..-VBForums
Results 1 to 8 of 8

Thread: MSFlexgrid - Set column width to text width..

  1. #1

    Thread Starter
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,370

    MSFlexgrid - Set column width to text width..

    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"

  2. #2
    Hyperactive Member
    Join Date
    Nov 2001
    Location
    Albany, NY
    Posts
    489
    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.

  3. #3

    Thread Starter
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,370
    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"

  4. #4

    Thread Starter
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,370
    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"

  5. #5
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Here is a Generic routine I've put together a while back:
    VB Code:
    1. Public Sub ResizeGrid(pGrid As MSFlexGrid, pForm As Form)
    2.     Dim intRow As Integer
    3.     Dim intCol As Integer
    4.    
    5.     With pGrid
    6.         For intCol = 0 To .Cols - 1
    7.             For intRow = 0 To .Rows - 1
    8.                 If .ColWidth(intCol) < pForm.TextWidth(.TextMatrix(intRow, intCol)) + 100 Then
    9.                    .ColWidth(intCol) = pForm.TextWidth(.TextMatrix(intRow, intCol)) + 100
    10.                 End If
    11.             Next
    12.         Next
    13.     End With
    14. End Sub

    Then just call this routine like this:


    ResizeGrid MSFlexGrid1, Form1

  6. #6

    Thread Starter
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,370
    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"

  7. #7
    Hyperactive Member rplcmint's Avatar
    Join Date
    Jan 2001
    Location
    Stockton, CA
    Posts
    333
    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.

  8. #8
    PowerPoster
    Join Date
    May 2002
    Posts
    25,528
    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...
    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.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * 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??? *

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.