Results 1 to 17 of 17

Thread: Format multiple mshflexgrid objects

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Format multiple mshflexgrid objects

    Hello. I want to format 12 diferent mshflexgrid with the same style. Can I do that using a procedure or do I have to format each object ?
    Thanks

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Format multiple mshflexgrid objects

    If you have the formatting code already, then you could do something like
    Code:
    Private Sub FormatGrid(pmshGridName As MshFlexGrid)
    'do formatting using the passed parameter of pmshGridName
    End Sub
    
    'then, in your program
    FormatGrid Mshflexgrid1

  3. #3

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Format multiple mshflexgrid objects

    Hello Hack. I've tried that, but it just doesn't work. I must say that the grids are in diferent forms because I'm using a MDI project (could it be for that?...).
    I've tried something like this:

    Code:
    Public Sub FormatGrid (FForms as form, FGrid as mshflexgrid)
    
    with fform.fgrid
       .....
       .....
    end with
    
    End Sub
    Can I do this, or should i do the formating for each form individually?

    Thank you.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Format multiple mshflexgrid objects

    If you are going to pass it a form name as well, then the syntax would be
    Code:
    FormatGrid Form1, MshFlexGrid1
    And make is a public sub in module.

  5. #5

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Format multiple mshflexgrid objects

    Yes, I've tried that way... I got the error message: "Compile error: Method or data member not found." Any sugestions?
    Thank you again.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Format multiple mshflexgrid objects

    On what line of code did the error occur?

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Format multiple mshflexgrid objects

    Nevermind....I just tested this and got the same error.

    You don't need to pass the form name. Just pass the grid name and you should be fine.

  8. #8

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Format multiple mshflexgrid objects

    Here it goes my code (error line 8) :

    vb Code:
    1. Public Sub Grid(GridHistorico As MSHFlexGrid)
    2. Dim i%, j%            
    3.  
    4. Dim r As Long          
    5. Dim c As Long          
    6. Dim cell_wid As Single  
    7. Dim col_wid As Single  
    8.  
    9.  
    10. With Consultas.GridHistorico  '### I got Error Message Here ###
    11.    
    12.     'começa a colorir o fundo da grid
    13.     DoEvents
    14.         If .Rows < 2 Then Exit Sub 'top row is a header
    15.             For j = 1 To .Rows - 1
    16.                 For i = 1 To .Cols - 1
    17.                     .Row = j
    18.                     .Col = i
    19.                 If j Mod 2 = 0 Then
    20.                     .CellBackColor = &HFAF5F1   'light green
    21.                 Else
    22.                     .CellBackColor = vbWhite
    23.                 End If
    24.                 Next i
    25.             Next j
    26.         .Row = 1
    27.         .Col = 1
    28. End With
    29.  
    30. 'formata espaçamento das celulas
    31. For c = 0 To Consultas.GridHistorico.Cols - 1
    32.     col_wid = 0
    33.     For r = 0 To Consultas.GridHistorico.Rows - 1
    34.         cell_wid = TextWidth(Consultas.GridHistorico.TextMatrix(r, c))
    35.         If col_wid < cell_wid Then col_wid = cell_wid
    36.     Next r
    37.     Consultas.GridHistorico.ColWidth(c) = col_wid + 120
    38. Next c
    39.  
    40.  
    41. End Sub
    Last edited by Hack; Mar 29th, 2007 at 09:54 AM. Reason: Changed [code] tags for [highlight=vb] tags to get the line numbering

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Format multiple mshflexgrid objects

    I changed your tags to get the line numbering. Take the form name off. Just use
    Code:
    With GridHistorico

  10. #10

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Format multiple mshflexgrid objects

    I got the same error...

    'formata espaçamento das celulas
    For c = 0 To GridHistorico.Cols - 1
    col_wid = 0
    For r = 0 To GridHistorico.Rows - 1
    cell_wid = TextWidth(GridHistorico.TextMatrix(r, c)) '##Error on "TextWidht
    If col_wid < cell_wid Then col_wid = cell_wid
    Next r
    GridHistorico.ColWidth(c) = col_wid + 120
    Next c

  11. #11
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Format multiple mshflexgrid objects

    TextWidth is a method of the Form object. Use

    cell_wid = GridHistorico.Parent.TextWidth(GridHistorico...

  12. #12

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Format multiple mshflexgrid objects

    Meanwhile, i've been trying and the color formatation works well. The collumns formt. still doesn't work. I'll keep trying...
    Thanks

  13. #13

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Format multiple mshflexgrid objects

    I've tried but it still not work... same error

    Code:
    For c = 0 To GridHistorico.Cols - 1
        col_wid = 0
        For r = 0 To GridHistorico.Rows - 1
            cell_wid = TextWidth(GridHistorico.Parent.TextMatrix(r, c)) '##Error on "TextWidht
            If col_wid < cell_wid Then col_wid = cell_wid
        Next r
    GridHistorico.ColWidth(c) = col_wid + 120
    Next c
    Thanks

  14. #14
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Format multiple mshflexgrid objects

    TextWidth is a method of the Form.

    cell_wid = GridHistorico.Parent.TextWidth(GridHistorico.TextMatrix(r, c))

  15. #15

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Re: Format multiple mshflexgrid objects

    Ok, i'm sorry ...
    Now is running but the collum enlargment effect is not working very well. Instead of stitching to the text widht , it shrinks to a few pixels. Any clue for that behavior?

    Thanks

  16. #16
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Format multiple mshflexgrid objects

    Unfortunately to be able to resize it accurately you need to do a bit more work than simply using TextWidth.. see the Autosize FlexGrid link in my signature for an explanation of some issues, and a sub that does all of resizing the work for you.

    The way you should call it in this case is like this:
    Code:
    FlexGrid_AutoSizeColumns GridHistorico, GridHistorico.Parent

  17. #17

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Resolved [Resolved] Re: Format multiple mshflexgrid objects

    Ok, that's it!
    You all rock.

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