Results 1 to 8 of 8

Thread: [RESOLVED] MSFlexGrid Help - Different Values/Same Procedure

  1. #1

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Resolved [RESOLVED] MSFlexGrid Help - Different Values/Same Procedure

    I have an MSFlexGrid on my form that holds data. When the user hit's the refresh button I call the function to populate the grid, but before doing so I need to erase the current contents and rows from the grid.

    I can clear the data from the grid using the .CLEAR, but I can't get the rows to get lost. The end result is that my "refresh" button just adds 31 more rows to the flexgrid.

    Here's my code to clear the flexgrid - as it stands right now. It seems to work okay, but when it gets to row 16 I get an error saying that there is no such row in the flexgrid. That's weird considering the flexgrid has 31 rows!

    VB Code:
    1. Public Sub ClearFLexGrid()
    2. Dim intCount As Integer
    3.  
    4. MSFlexSummary.Clear
    5.   For intCount = 0 To MSFlexSummary.Rows - 1
    6.        MSFlexSummary.RemoveItem (intCount)
    7.   Next
    8. End Sub

    UPDATE - Sorry, my error is "Cannot perform an update on a fixed row"
    Last edited by The_Grudge; Oct 26th, 2006 at 09:55 AM.

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Remove Rows MSFlexGrid

    I use .CLEAR, followed by .ROWS = 1 and .COLS=1

    I use the 1 value probably because .FIXEDROWS is 1 and setting .ROWS to 0 would blow up...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Remove Rows MSFlexGrid

    Quote Originally Posted by szlamany
    I use the 1 value probably because .FIXEDROWS is 1 and setting .ROWS to 0 would blow up...
    I just realized a couple of hours ago that it's not like that. It doesn't allow you during design-time but it does during run-time. Don't have a clue why so...

  4. #4

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Remove Rows MSFlexGrid

    Okay, so a user opens the form and the MSFlexGrid works like a charm. Then when they hit the refresh button everything works perfectly except the first record disappears....howcome?

    VB Code:
    1. Private Sub cmdRefresh_Click()
    2.   ClearFlexGrid
    3.   MSFlexSummary.Refresh
    4.   Form_Load
    5. End Sub
    6.  
    7. Private Sub Form_Load()
    8.  Dim strSQL As String
    9.  Dim intTotal As Integer
    10.  Dim rsDateSummary As New ADODB.Recordset
    11.  Dim lngCol As Long
    12.  Dim lngRow As Long
    13.  Dim booOldRedraw As Boolean
    14.    
    15.  Set rsDateSummary = New ADODB.Recordset
    16.  
    17.  lblDate = Format(frmMainScreen.mebDate, "MMMM D,YYYY")
    18.  
    19.  With MSFlexSummary
    20.   'Setup the required number of columns
    21.   .Cols = 2
    22.   .FixedCols = 0
    23.  
    24.   .Font.Bold = True
    25.   .TextMatrix(0, 0) = "Sub-Service"
    26.   .TextMatrix(0, 1) = "Total"
    27.   .FontBold = False
    28.  
    29.   'Turn off screen updates (much faster to fill the data)
    30.   booOldRedraw = .Redraw
    31.   .Redraw = False
    32.  
    33.   strSQL = "select PROD.BEDS_NU_SERV_OCC.DATE_CAPTURED, PROD.BEDS_NU_SERV_OCC.SUB_SERVICE, " & _
    34.            "SUM (PROD.BEDS_NU_SERV_OCC.OCC) As OCC, PROD.BEDS_MAP_SUB_SERV_TO_SERV.SHEET_ORDER " & _
    35.            "from PROD.BEDS_MAP_SUB_SERV_TO_SERV, PROD.BEDS_NU_SERV_OCC " & _
    36.            "where PROD.BEDS_NU_SERV_OCC.DATE_CAPTURED = To_Date ('" & lblDate & "','MM/DD/YYYY') " & _
    37.            "and PROD.BEDS_NU_SERV_OCC.SUB_SERVICE = PROD.BEDS_MAP_SUB_SERV_TO_SERV.SUB_SERVICE (+) " & _
    38.            "group by PROD.BEDS_NU_SERV_OCC.DATE_CAPTURED, PROD.BEDS_NU_SERV_OCC.SUB_SERVICE, " & _
    39.            "PROD.BEDS_MAP_SUB_SERV_TO_SERV.SHEET_ORDER order by 1, 2"
    40.  
    41.   rsDateSummary.Open strSQL, OraCon, adOpenForwardOnly, adLockReadOnly
    42.  
    43.  
    44.   If rsDateSummary.EOF Then
    45.      'If there is no data, only allow the required blank row, and hide it (height = 0)
    46.      .AddItem ""
    47.      .RemoveItem .FixedRows
    48.      .RowHeight(.FixedRows) = 0
    49.   Else
    50.     'We have data, add it one row at a time
    51.     lngRow = .Rows
    52.       Do While Not rsDateSummary.EOF
    53.         'Add the row (empty)
    54.          .AddItem ""
    55.         'Set the values one cell at a time
    56.          
    57.            .TextMatrix(lngRow, lngCol) = rsDateSummary.Fields!SUB_SERVICE
    58.            .TextMatrix(lngRow, lngCol + 1) = rsDateSummary.Fields!OCC
    59.            intTotal = intTotal + rsDateSummary.Fields!OCC
    60.  
    61.          'Increment Row Counter
    62.           lngRow = lngRow + 1
    63.          'Move to the next row of data
    64.           rsDateSummary.MoveNext
    65.      Loop
    66.      
    67.     'Remove the blank row we left at the top
    68.      .RemoveItem .FixedRows
    69.  End If
    70.  
    71.  'Re-enable screen updates
    72.  .Redraw = booOldRedraw
    73.  'Force redraw of grid
    74.  .Refresh
    75. End With
    76.  
    77. lblTotal = intTotal
    78.  
    79. End Sub
    80.  
    81. Public Sub ClearFlexGrid()
    82. Dim intCount As Integer
    83.   MSFlexSummary.Clear
    84.   MSFlexSummary.Rows = 1
    85.   MSFlexSummary.Cols = 0
    86. End Sub

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Remove Rows MSFlexGrid

    You have no heading row at the top?

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: Remove Rows MSFlexGrid

    You have no heading row at the top?
    It's there....just buried.

    VB Code:
    1. .TextMatrix(0, 0) = "Sub-Service"
    2. .TextMatrix(0, 1) = "Total"

  7. #7

    Thread Starter
    Fanatic Member The_Grudge's Avatar
    Join Date
    Jan 2005
    Location
    Canada
    Posts
    836

    Re: [RESOLVED] MSFlexGrid Help - Different Values/Same Procedure

    The problem was that

    VB Code:
    1. Public Sub ClearFlexGrid()
    2. Dim intCount As Integer
    3.   MSFlexSummary.Clear
    4.   MSFlexSummary.Rows = 1
    5.   MSFlexSummary.Cols = 0
    6. End Sub

    Should have read

    VB Code:
    1. Public Sub ClearFlexGrid()
    2. Dim intCount As Integer
    3.   MSFlexSummary.Clear
    4.   MSFlexSummary.Rows = 2
    5.   MSFlexSummary.Cols = 2
    6. End Sub

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: MSFlexGrid Help - Different Values/Same Procedure

    It's hard to follow what you are doing with your manipulation of .ROW and lngROW and filling the row with .TEXTMATRIX() array...

    We've had several other threads over the years on .ROW manipulation and the problems that creates...

    Here's one:

    http://www.vbforums.com/showthread.p...light=.additem

    .ADDITEM should be used to add rows - with data - all at once.

    .FORMATSTRING should be used to create the heading row data.

    The problems you are having - 1 vs 2 vs FIXEDROW have been discussed before...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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