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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MSFlexgrid column width not changing 2

Status
Not open for further replies.

Bluejay07

Programmer
Mar 9, 2007
780
CA
Hello,

I am currently modifying a form with an msflexgrid. The form works as is, however it doesn't like my changes.
Code:
msfgOptions.Clear
   
If m_bolChargeType Then
   msfgOptions.FormatString = 
"^Active    |<Code                    |<Name                                    |<GL Account        "
   msfgOptions.Cols = 4
Else
   msfgOptions.FormatString = "^Active    |<Code                    |<Name                                                                     "
   msfgOptions.Cols = 3
End If

Previously, the formatstring and number of columns didn't exist in code, only in the properties section in the IDE.

The formatstring with three columns is what the grid originally had. I am adding a new column and changing the spacing of 'Name' so it will all fit.

The flex grid has just enough space at the end of name to accomodate the verticle scroll bar. When I add a fourth column, the grid treats it the exact same as the previous formatstring except it doesn't adjust the column width. In the empty space where the scroll bar goes, it adds 'GL'.

If I add a horizontal scroll bar, I can see the entire column but this isn't what I want. There is no code to set the form width and I haven't encountered this issue with other grids in the past.

What may I be overlooking?

Thanks.

If at first you don't succeed, then sky diving wasn't meant for you!
 

Try:
Code:
With msfgOptions
    .Clear
    If m_bolChargeType Then
         .Cols = 4
        .FormatString = "^Active |< Code |<Name |<GL Account"
        .ColWidth(0) = .Width / 4   
        .ColWidth(1) = .Width / 4   
        .ColWidth(2) = .Width / 4   
        .ColWidth(3) = .Width / 4   
    Else
        .Cols = 3
        .FormatString = "^Active |<Code |< Name"
        .ColWidth(0) = .Width / 3   
        .ColWidth(1) = .Width / 3   
        .ColWidth(2) = .Width / 3       
    End If
End With

Of course i you may want to use other values than 4 or 3 to set the Width of your columns.

Have fun.

---- Andy
 
Hi Andy,

Thanks for the reply. Your solution does work and could be a possibility, however, this posses a few conflicts.
First off, since the columns are now uniform in size, some columns - such the the first column, are now greater in size than are needed. In addition, the scroll bar is now placed on top of the last column instead of beside it. The form has a floating text box for the grid cells, which is also why that additional space is required, and is now overlapping the scroll bar.

The formatstring spacing is exactly how I want it when tested in the IDE.

Any other suggestions?

If at first you don't succeed, then sky diving wasn't meant for you!
 
Although if I play with the widths, I can get it to work.
Code:
msfgOptions.ColWidth(0) = (msfgOptions.Width - 1800) / 4
msfgOptions.ColWidth(1) = (msfgOptions.Width - 800) / 4
msfgOptions.ColWidth(2) = (msfgOptions.Width + 1800) / 4
msfgOptions.ColWidth(3) = (msfgOptions.Width - 800) / 4

If at first you don't succeed, then sky diving wasn't meant for you!
 

3 and 4 was just the suggestion, use your numbers instead

I usually do[tt]
.ColWidth(1) = .Width * 0.28[/tt] - 28% of the Width of the Grid

You can set the ColWidth your way, but I would avoid using *magic numbers* (1800, 800, etc.) because they will only work on the monitor with the same resolution as yours. Reset your monitor to another res and see what will happen.

(I know - 0.28 is another *magic number* :) )

'Floating text box' IS the problem, but you can assign the Height and Width (you should already have the Top and Left) of it 'on-the-fly' in the code so it will always match the size of your cell in your Grid.

Have fun.

---- Andy
 
Thank you very much for your comments and suggestions.

If at first you don't succeed, then sky diving wasn't meant for you!
 
How about something like ...

Const m_bolChargeType = True 'flip this value manually for testing

Private Sub Form_Load()

Dim w, h
Dim nrows2show

msfgOptions.Clear
msfgOptions.Rows = 10
nrows2show = 3

If m_bolChargeType Then
msfgOptions.FormatString = "^Active |<Code |<Name |<GL Account "
msfgOptions.Cols = 4
Else
msfgOptions.FormatString = "^Active |<Code |<Name "
msfgOptions.Cols = 3
End If

'assume gridlines are one pixel high/ wide

w = Screen.TwipsPerPixelX
For i = 0 To msfgOptions.Cols - 1
w = w + msfgOptions.ColWidth(i) + Screen.TwipsPerPixelX
Next

h = Screen.TwipsPerPixelY + nrows2show * (msfgOptions.RowHeight(0) + Screen.TwipsPerPixelY)

If msfgOptions.Rows > nrows2show Then w = w + 290 'vert scroll bar is about 290 twips wide

msfgOptions.Width = w
msfgOptions.Height = h

End Sub
 

HughLerwill,
That's another way to go, but why do you suggest to use m_bolChargeType, w, h, and nrows2show - all of them As Variant? They can have a particular type assign, I would guess Boolean and Integer(s)


Have fun.

---- Andy
 
Thank you HughLerwill for posting a possible alternate solution. The more options I am presented with, the more I can try various solutions.

If at first you don't succeed, then sky diving wasn't meant for you!
 
Andy - Of course, pure laziness on my part when I put together the example I'm afraid. Incidentally Const m_bolChargeType = True or False returns VarType = 11 = Boolean for m_bolChargeType.

On reflection I might change

If msfgOptions.Rows > nrows2show Then w = w + 290 'vert scroll bar is about 290 twips wide

to

If msfgOptions.Rows > nrows2show Then w = w + 24 * Screen.TwipsPerPixelX 'vert scroll bar is about 24 pixels wide

To make things stay sweet when TwipsPerPixelX has a value other than 12.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top