Stunning! Thanks a million Rick that's a massive help :)

Colin



----- Original Message -----
From: "Rick Rose" <[EMAIL PROTECTED]>
To: [email protected]
Subject: Re: [vbhelp] re: Another MSHFlexGrid Question
Date: Mon, 14 Feb 2005 17:49:16 -0500

> 
> Here is the code to automatically size the columns of an MSHFlexgrid.
> 
> Public Sub ResizeColumn(ColNumber As Long, FlexAdd As MSHFlexGrid)
>      Dim CurrentRow As Long
>      Dim CurrentCol As Long
>      Dim ColText As String
>      Dim Fnt As Object
>      With FlexAdd
>          CurrentRow = .Row
>          CurrentCol = .Col
>          .Row = 0
>          .Col = ColNumber
>          .RowSel = .Rows - 1
>          .ColSel = ColNumber
>          ColText = .Clip
>          Set Fnt = .Parent.Font
>          Set .Parent.Font = .Font
>          .ColWidth(ColNumber) = .Parent.TextWidth(ColText)
>          If .ColWidth(ColNumber) > 0 Then
>              .ColWidth(ColNumber) = .ColWidth(ColNumber) + _
>                  6 * Screen.TwipsPerPixelX + 200
>          End If
>          Set .Parent.Font = Fnt
>          .Row = CurrentRow
>          .Col = CurrentCol
>      End With
> End Sub
> 
> Usage:
> 
>      For x = 1 To FlexAdd.Cols - 2
>          ResizeColumn x, FlexAdd
>          y = y + FlexAdd.ColWidth(x)
>      Next x
> 
> I don't remember if " y = y + FlexAdd.ColWidth(x)" is important, or not, but
> I've added it just in case.  FlexAdd was the name of the MSHFlexgrid
> 
> 
> Rick Rose
> -------Original Message-------
> 
> From: Colin Jackson
> Date: 02/14/05 17:10:21
> To: [email protected]
> Subject: [vbhelp] re: Another MSHFlexGrid Question
> 
> 
> Hi Folks,
> 
> I want to resize an MSHFlexGrid Column to the width of a given string. I'd
> have expected there to be a feature of the control to do this, but if there
> is I can't see it.
> 
> I've tried various approaches, such as converting the length of the string
> to points (by getting the fontwidth value for the control and multiplying by
> the number of chars), then *20 to give a twips value (which is what the
> ColWidth property expects) but the problem is that the text width varies
> from character to character (I think that's the problem anyway), so the
> results are erratic.
> 
> Can anybody think of an elegant way to do it? I do have a way to do it, but
> it's so crazy, tortuous and inelegant I'm reluctant to implement it if there
> s a simple way :)
> 
> Any pointers in the right direction greatfully received.
> 
> Cheers
> Colin
> 
> --
> ___________________________________________________________
> Sign-up for Ads Free at Mail.com
> http://promo.mail.com/adsfreejump.htm
> 
> 
> 
> 
> 
> 
> 
> '// =======================================================
>      Rules : http://ReliableAnswers.com/List/Rules.asp
>      Home  : http://groups.yahoo.com/group/vbHelp/
>      =======================================================
>      Post  : [email protected]
>      Join  : [EMAIL PROTECTED]
>      Leave : [EMAIL PROTECTED]
> '// =======================================================
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 
> 
> 
> 
> [Non-text portions of this message have been removed]

-- 
___________________________________________________________
Sign-up for Ads Free at Mail.com
http://promo.mail.com/adsfreejump.htm




'// =======================================================
    Rules : http://ReliableAnswers.com/List/Rules.asp
    Home  : http://groups.yahoo.com/group/vbHelp/
    =======================================================
    Post  : [email protected]
    Join  : [EMAIL PROTECTED]
    Leave : [EMAIL PROTECTED]
'// =======================================================
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/vbhelp/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to