Results 1 to 14 of 14

Thread: [RESOLVED] Flexgrid Column Width

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Resolved [RESOLVED] Flexgrid Column Width

    I have some data going into a felxgrid and need the columnc big enough to be able to see the entire data being entered.

    How would i do this?

    Cheers
    ILMV aka <insert aka name here>

  2. #2

  3. #3

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Flexgrid Column Width

    Ok then, i will try that.

    Cheeers - IMLV

  4. #4
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Flexgrid Column Width

    Here is a routine I use to adjust the HEIGHT of FlexGrid row in order to accomodate variable text (this would go in a module) :
    VB Code:
    1. '-----------------------------------------------------------------------------
    2. Public Sub AdjustGridRowHeight(pobjGrid As MSFlexGrid, _
    3.                                pobjLabel As Label, _
    4.                                plngRow As Long, _
    5.                                plngCol As Long, _
    6.                                Optional pblnAddNewLine As Boolean = False)
    7. '-----------------------------------------------------------------------------
    8.    
    9.     ' Adjusts the height of a flexgrid row, using the height required by a
    10.     ' label using the same font, fontsize, and width. The label used must have
    11.     ' Autosize and WordWrap set to True.
    12.     ' Also, the WordWrap property of the flexgrid must be set to True.
    13.    
    14.     With pobjGrid
    15.         .Row = plngRow
    16.         .Col = plngCol
    17.         pobjLabel.FontName = .CellFontName
    18.         pobjLabel.FontSize = .CellFontSize
    19.         pobjLabel.Width = .CellWidth
    20.         pobjLabel.Caption = .Text & IIf(pblnAddNewLine, vbNewLine, "")
    21.         If pobjLabel.Height > .RowHeight(.Row) Then
    22.             .RowHeight(.Row) = pobjLabel.Height
    23.         End If
    24.     End With
    25.    
    26. End Sub
    27.  
    28. ' This is another routine I use sometimes to assign text to a cell
    29.  
    30. '-----------------------------------------------------------------------------
    31. Public Sub SetCellText(pobjGrid As MSFlexGrid, _
    32.                        plngRow As Long, _
    33.                        plngCol As Long, _
    34.                        pstrText As String, _
    35.                        Optional pblnBold As Boolean = False, _
    36.                        Optional plngAlignment _
    37.                              As MSFlexGridLib.AlignmentSettings = flexAlignLeftTop)
    38. '-----------------------------------------------------------------------------
    39.    
    40.     With pobjGrid
    41.         .Row = plngRow
    42.         .Col = plngCol
    43.         .Text = pstrText
    44.         .CellFontBold = pblnBold
    45.         .CellAlignment = plngAlignment
    46.     End With
    47.  
    48. End Sub

    In a form - need a FlexGrid and a Label. Assumes the following:
    GRID
    (1) grid is called grdNotes
    (2) FixedCols set to 0
    (3) WordWrap set to True
    LABEL
    (1) Named lblCellText
    (2) AutoSize set to True
    (3) WordWrap set to True
    (4) Visible set to False

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     grdNotes.Redraw = False
    4.    
    5.     With grdNotes
    6.         .Rows = 1
    7.         .Cols = 3
    8.         .ColWidth(0) = .Width \ 3
    9.         .ColWidth(1) = .Width \ 3
    10.         .ColWidth(2) = .Width \ 3
    11.     End With
    12.    
    13.     SetCellText grdNotes, 0, 0, "Date/Time", True
    14.     SetCellText grdNotes, 0, 1, "Contact", True
    15.     SetCellText grdNotes, 0, 2, "Notes", True
    16.    
    17.    
    18.     ' Typically, you would load the grid in by looping thru a recordset or file.
    19.     ' In this example, 3 records are loaded "manually" ...
    20.    
    21.     grdNotes.Rows = grdNotes.Rows + 1
    22.     SetCellText grdNotes, 1, 0, "8/10/2005"
    23.     SetCellText grdNotes, 1, 1, "John Smith"
    24.     SetCellText grdNotes, 1, 2, "j asdf dsflaks jfalskjf lasjdfaslfj asdfjasdfjsadf asdfasdf" _
    25.                               & "asdf asdf asdfasdfkasdf aslkfas;ldfkasldfkasf werw er wdf " _
    26.                               & "dsaf wer wdf awr adf aserfawdf;la mcvas;ldkas;rkwerwer"
    27.     AdjustGridRowHeight grdNotes, lblCellText, 1, 2
    28.  
    29.     grdNotes.Rows = grdNotes.Rows + 1
    30.     SetCellText grdNotes, 2, 0, "8/11/2005"
    31.     SetCellText grdNotes, 2, 1, "Bob Jones"
    32.     SetCellText grdNotes, 2, 2, "j asdf dsflaks jfalskjf lasjdfaslfj asdfjasdfjsadf asdfasdf"
    33.     AdjustGridRowHeight grdNotes, lblCellText, 2, 2
    34.  
    35.     grdNotes.Rows = grdNotes.Rows + 1
    36.     SetCellText grdNotes, 3, 0, "8/13/2005"
    37.     SetCellText grdNotes, 3, 1, "Mary Belle"
    38.     SetCellText grdNotes, 3, 2, "j asdf dsflaks jfalskjf lasjdfaslfj asdfjasdfjsadf asdfasdf" _
    39.                               & "asdf asdf asdfasdfkasdf aslkfas;ldfkasldfkasf werw er wdf " _
    40.                               & "dsaf wer wdf awr adf aserfawdf;la mcvas;ldkas;rkwerwer" _
    41.                               & "asdf asdf asdfasdfkasdf aslkfas;ldfkasldfkasf werw er wdf " _
    42.                               & "dsaf wer wdf awr adf aserfawdf;la mcvas;ldkas;rkwerwer"
    43.     AdjustGridRowHeight grdNotes, lblCellText, 3, 2
    44.  
    45.  
    46.     grdNotes.Redraw = True
    47.  
    48. End Sub

    For good measure, I attached a sample project using the above code. I hope this helps.
    Attached Files Attached Files
    "It's cold gin time again ..."

    Check out my website here.

  5. #5

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Flexgrid Column Width

    VB Code:
    1. Public Sub DisplayGrid()
    2.     Dim i, j As Single
    3.    
    4.     If MySearch.RecordCount > 0 Then                            'Checks to see if greater than zero
    5.         MySearch.MoveLast                                       'Moves to last record in recordset
    6.         MySearch.MoveFirst                                      'And then moves to first record in recordset
    7.             'Below: Dynamically size flexgrid to recordset size
    8.         MSFlexGrid1.Cols = (MySearch.Fields.Count)
    9.         MSFlexGrid1.Rows = MySearch.RecordCount + 1
    10.             'Below: Populate column headings with field names
    11.         MSFlexGrid1.Row = 0
    12.         For i = 0 To MySearch.Fields.Count - 1
    13.             MSFlexGrid1.Col = i
    14.             MSFlexGrid1.Text = MySearch.Fields(i).Name
    15.             MSFlexGrid1.ColWidth(i) = Len(MSFlexGrid1.Text) * ColWidthRatio
    16.         Next i
    17.             'Below: Populate flexgrid with recordset data
    18.            
    19.            
    20.         For i = 0 To MySearch.RecordCount - 1
    21.             MSFlexGrid1.Row = i + 1
    22.                 For j = 0 To MySearch.Fields.Count - 1
    23.                     MSFlexGrid1.Col = j
    24.                     If Not MySearch.Fields(j) = " " Then
    25.                         MSFlexGrid1.Text = MySearch.Fields(j)
    26.                         If MSFlexGrid1.ColWidth(j) < Len(MSFlexGrid1.Text) * ColWidthRatio Then MSFlexGrid1.ColWidth(j) = Len(MSFlexGrid1.Text) * ColWidthRatio
    27.                     Else
    28.                         MSFlexGrid1.Text = " "
    29.                     End If
    30.                 Next j
    31.             MySearch.MoveNext
    32.         Next i
    33.        
    34.        
    35.     Else
    36.         MsgBox "There are no records for the parameter you selected", vbExclamation, "Grid Populate Error"
    37.         'Displays message box with OK button and Exclamation icon.
    38.     End If
    39.     SQLTXT = ""                                                 'Set recordset to nothing to be safe
    40.    
    41.     Call FormatFlex
    42. End Sub

    This is the code i am currently using, provided by my teacher, but i thinks its crap because if the width is smaller then the flexgrid width (for that column)
    it doesnt just make it just big enough, it goes further, making the entire width of the flexgrid huge, when it doesnt have to be.
    And that isnt very user friendly, having to scroll all the way across to see the information.

    How can i change this, so that it wuold still check to see if the column is big enough, but if it isnt make the widht just big enough?

    Thank you
    ILMv

  6. #6

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Flexgrid Column Width

    Anyone?

    ILMV

  7. #7
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Flexgrid Column Width

    Hey ILMV,
    I have adjusted my example to include a new routine "AdjustGridColWidth". This should help you do what you are looking for. (Note that in addition to the use of this new routine, the WordWrap property of both the Label and the grid must now = False.)
    Attached Files Attached Files
    "It's cold gin time again ..."

    Check out my website here.

  8. #8

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Flexgrid Column Width

    cheers BruceG, but i have problems, i have put the sub's in my global module

    VB Code:
    1. For i = 0 To MySearch.RecordCount - 1
    2.             MSFlexGrid1.Row = i + 1
    3.                 For j = 0 To MySearch.Fields.Count - 1
    4.                     MSFlexGrid1.Col = j
    5.                     If Not MySearch.Fields(j) = " " Then
    6.                        
    7.                         MSFlexGrid1.Redraw = False
    8.                        
    9.                         SetCellText MSFlexGrid1, [B]i, j[/B], MySearch.Fields(j)
    10.                         AdjustGridColWidth MSFlexGrid1, lblCellText, [B]i, j[/B]
    11.    
    12.                         MSFlexGrid1.Redraw = True
    13.                         'MSFlexGrid1.Text = MySearch.Fields(j)
    14.                         'AdjustGridColWidth MSFlexGrid1, lblCellText, i, j
    15.                        
    16.                         'If MSFlexGrid1.ColWidth(j) < Len(MSFlexGrid1.Text) * ColWidthRatio Then MSFlexGrid1.ColWidth(j) = Len(MSFlexGrid1.Text) * ColWidthRatio
    17.                     Else
    18.                         MSFlexGrid1.Text = " "
    19.                     End If
    20.                 Next j
    21.             MySearch.MoveNext
    22.         Next i

    But i get an error on the i, and j letters here. (bold)

  9. #9
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Flexgrid Column Width

    What does the error say?

  10. #10

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Flexgrid Column Width

    Oh, sorry it is sorted now. It was because i didnt know exactly what was going on, but after alot of head banging andd staring ar GBruceyG's code, i know no what the hell it does Cheers Bruce, and everyone for your replies, much appreciated.

  11. #11
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: [RESOLVED] Flexgrid Column Width

    Headbanging helps most of the times

  12. #12

  13. #13
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: [RESOLVED] Flexgrid Column Width

    Glad u worked it out.
    "It's cold gin time again ..."

    Check out my website here.

  14. #14

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: [RESOLVED] Flexgrid Column Width

    well spotted MLiss, but they were further up the page

    Cheers for your help bruce, we got about 40 people doing this at college, and they are all doing it the stupid way, god help them

Posting Permissions

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



Click Here to Expand Forum to Full Width