Results 1 to 16 of 16

Thread: [RESOLVED] MSFlexGrid Row Anomalys

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Resolved [RESOLVED] MSFlexGrid Row Anomalys

    Anyone had any when updating a msflexgrid (which includes clearing then re-populating).

    I keep having rows pop out of nowhere, and when I click on my re-populate query, they subquentially go from one less row to the correct number...

    In general I'm having all sorts of bugs, prob which are attributed to my code,

    Currently here is my main code that writes to the flexgrid.

    VB Code:
    1. Private Function WriteShow(pShow As String)
    2.     Debug.Print "Writing Show"
    3.     On Error GoTo Error
    4.    
    5.     If Selection = Show_Name Then
    6.         'TreeView.SelectedItem.Next
    7.         'TreeView.SelectedItem.Next
    8.         'TreeView.SelectedItem.Next
    9.         Selection = Show_Name & ".Rundown"
    10.     End If
    11.    
    12.     FlexGridDone = False
    13.    
    14.    
    15.    
    16.    
    17.     Dim Counter As Integer
    18.     Dim Counter2 As Integer 'For Refresing of FlexGrid
    19.     Dim Total As Integer
    20.     'Remove All Items Cept The First Top Item!
    21.    
    22.     Counter2 = 2
    23.    
    24.     Total = MSFlexGrid1.Rows
    25.    
    26.     'Remove all items?
    27.     If Total >= 1 Then
    28.         Do Until Counter2 = MSFlexGrid1.Rows
    29.             MSFlexGrid1.RemoveItem (Counter2)
    30.             Counter2 = Counter2 + 1
    31.         Loop
    32.     End If
    33.    
    34.     'Act Normal
    35.     cn.Open
    36.     SQL = "SELECT * FROM `Rundown` WHERE `Show` = '" & Show_Name & "' ORDER BY `Pos` ASC"
    37.    
    38.     rs.Open SQL, cn, adOpenForwardOnly, adLockOptimistic
    39.     Counter2 = 0
    40.    
    41.     'MSFlexGrid1.RemoveItem
    42.     Counter = 1
    43.     With rs
    44.         Do Until rs.EOF = True
    45.             MSFlexGrid1.AddItem ("")
    46.             'Fill In the Col. Data.
    47.                 MSFlexGrid1.TextMatrix(Counter, 2) = !Tal
    48.                 MSFlexGrid1.TextMatrix(Counter, 3) = !Slug
    49.                 MSFlexGrid1.TextMatrix(Counter, 4) = !Format
    50.                 MSFlexGrid1.TextMatrix(Counter, 5) = !Graphics
    51.                 MSFlexGrid1.TextMatrix(Counter, 6) = !Status
    52.                 MSFlexGrid1.TextMatrix(Counter, 7) = !Tape
    53.                 MSFlexGrid1.TextMatrix(Counter, 8) = !SOT
    54.                 MSFlexGrid1.TextMatrix(Counter, 9) = !Read
    55.                 MSFlexGrid1.TextMatrix(Counter, 13) = !autonumber
    56.                 '.TextMatrix(Counter, 2) =
    57.             'Go To New Row
    58.             'Fill First Col With Data
    59.             Counter = Counter + 1
    60.             .MoveNext
    61.         Loop
    62.        
    63.     End With
    64.    
    65.    
    66.     Dim Total_Results As Integer
    67.     Total_Results = Counter - 1
    68.     rs.Close
    69.     cn.Close
    70.    
    71.    
    72.     'Fix for wierd cell bug
    73.     MSFlexGrid1.Row = 1
    74.     MSFlexGrid1.Col = 1
    75.     MSFlexGrid1.CellBackColor = RGB(255, 255, 255)
    76.    
    77.    
    78.     'Possibly Fix another bad FlexGrid Bug?
    79.     If MSFlexGrid1.Rows >= Total_Results Then
    80.         MSFlexGrid1.RemoveItem (MSFlexGrid1.Rows)
    81.     End If
    82.    
    83.     If Not MSFlexGrid1.Rows = Total_Results Then
    84.         WriteShow (Show_Name)
    85.         MSFlexGrid1.Redraw = True
    86.         MSFlexGrid1.Refresh
    87.     End If
    88.    
    89.     'Fix another flexgrid bug we've developed!
    90.     'Remove all rows w/o Identifer
    91.     'Dim Counter3 As Integer
    92.     'Counter3 = 2
    93.     'Do Until Counter3 = MSFlexGrid1.Cols
    94.     '    If MSFlexGrid1.TextMatrix(Counter3, 13) = "" Then
    95.     ''        MSFlexGrid1.RemoveItem (MSFlexGrid1.Row)
    96.      '   End If
    97.     ' '   Counter3 = Counter3 + 1
    98.     'Loop
    99.    
    100.     FlexGridDone = True
    101.     FillGrid = True
    102.     MSFlexGrid1.Redraw = True
    103.     MSFlexGrid1.Refresh
    104.    
    105. Error:
    106.     If Err.Number = 30002 Then
    107.         MSFlexGrid1.Redraw = True
    108.         MSFlexGrid1.Refresh
    109.         FlexGridDone = True
    110.         FillGrid = True
    111.     End If
    112.         MSFlexGrid1.Redraw = True
    113.         MSFlexGrid1.Refresh
    114.         FlexGridDone = True
    115.         FillGrid = True
    116.         'Debug.Print "Another FlexGrid Error " & Err.Number & " " & Err.Description
    117. End Function

    Sorry I know it's crappy. It would be more suitable to zip up the code and ship it off for help. However I'm referencing a database and it may not show just correctly. However I may let someone here on these forums to VNC in if they would like... that's a worst case senario though... HOpefully someone can find something in this block of code and help me understand why my code doesn't work... I know it must be my code and not FlexGrid!

  2. #2
    Hyperactive Member
    Join Date
    May 2005
    Posts
    324

    Re: MSFlexGrid Row Anomalys

    Could this:
    Total = MSFlexGrid1.Rows

    'Remove all items?
    If Total >= 1 Then
    Do Until Counter2 = MSFlexGrid1.Rows
    MSFlexGrid1.RemoveItem (Counter2)
    Counter2 = Counter2 + 1
    Loop
    End If
    be the problem?

    I would use:
    Total = MSFlexGrid1.Rows

    'Remove all items?
    For x = Total to 1 Step -1
    MSFlexGrid1.RemoveItem (x)
    Next x

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: MSFlexGrid Row Anomalys

    Your Code prevents any of my rows from showing (except the required first one, which shows up blank; which is wrong), that code I'm using only shows 1/2 of them

  4. #4
    Hyperactive Member
    Join Date
    May 2005
    Posts
    324

    Re: MSFlexGrid Row Anomalys

    Sorry, I thought from the commented line that you wanted to remove all of the existing rows from the grid before repopulating it. I'm sorry, I didn't read all of your code, and that just jumped out.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: MSFlexGrid Row Anomalys

    that's what I want to do though.

    I was patching the code as you see later to remove false lines where there was no data populated back from the sql server.

    This function is to remove all code, then repopulate it. I have a treeview next to the code that is called, it strings to the writeshow function the show that needs to be populated. That is why you see a SQL query inside the code.

  6. #6

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: MSFlexGrid Row Anomalys

    Eureka! Why haven't I seen that before! Now the code Infitely loops and crashes.

    [Removed Stupid Function]

    I find thinking too much outside the box, and creating my own way to remove items when a function exists exhausing... Must stop that!
    Last edited by DJHotIce; Nov 8th, 2005 at 04:24 PM.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: MSFlexGrid Row Anomalys

    Resolved somewhat... here is the current function... I needed to remove the infite loop that causes it to restart the function...

    VB Code:
    1. Private Function WriteShow(pShow As String)
    2.     Debug.Print "Writing Show"
    3.     On Error GoTo Error
    4.    
    5.     If Selection = Show_Name Then
    6.         Selection = Show_Name & ".Rundown"
    7.     End If
    8.    
    9.     FlexGridDone = False
    10.    
    11.    
    12.    
    13.    
    14.     Dim Counter As Integer
    15.     Dim Counter2 As Integer 'For Refresing of FlexGrid
    16.     Dim Total As Integer
    17.    
    18.    
    19.     Counter2 = 2
    20.    
    21.     Total = MSFlexGrid1.Rows
    22.    
    23.     'Remove All Items Cept The First Top Item!
    24.     MSFlexGrid1.Clear
    25.    
    26.     'Act Normal
    27.     cn.Open
    28.     SQL = "SELECT * FROM `Rundown` WHERE `Show` = '" & Show_Name & "' ORDER BY `Pos` ASC"
    29.    
    30.     rs.Open SQL, cn, adOpenForwardOnly, adLockOptimistic
    31.     Counter2 = 0
    32.    
    33.     'MSFlexGrid1.RemoveItem
    34.     Counter = 1
    35.     With rs
    36.         Do Until rs.EOF = True
    37.             MSFlexGrid1.AddItem ("")
    38.             'Fill In the Col. Data.
    39.                 MSFlexGrid1.TextMatrix(Counter, 2) = !Tal
    40.                 MSFlexGrid1.TextMatrix(Counter, 3) = !Slug
    41.                 MSFlexGrid1.TextMatrix(Counter, 4) = !Format
    42.                 MSFlexGrid1.TextMatrix(Counter, 5) = !Graphics
    43.                 MSFlexGrid1.TextMatrix(Counter, 6) = !Status
    44.                 MSFlexGrid1.TextMatrix(Counter, 7) = !Tape
    45.                 MSFlexGrid1.TextMatrix(Counter, 8) = !SOT
    46.                 MSFlexGrid1.TextMatrix(Counter, 9) = !Read
    47.                 MSFlexGrid1.TextMatrix(Counter, 13) = !autonumber
    48.                 '.TextMatrix(Counter, 2) =
    49.             'Go To New Row
    50.             'Fill First Col With Data
    51.             Counter = Counter + 1
    52.             .MoveNext
    53.         Loop
    54.        
    55.     End With
    56.    
    57.    
    58.     Dim Total_Results As Integer
    59.     Total_Results = rs.RecordCount
    60.     rs.Close
    61.     cn.Close
    62.    
    63.    
    64.     'Fix for wierd cell bug
    65.     MSFlexGrid1.Row = 1
    66.     MSFlexGrid1.Col = 1
    67.     MSFlexGrid1.CellBackColor = RGB(255, 255, 255)
    68.    
    69.    
    70.     'Possibly Fix another bad FlexGrid Bug?
    71.     If MSFlexGrid1.Rows >= Total_Results + 1 Then
    72.         MSFlexGrid1.RemoveItem (MSFlexGrid1.Rows)
    73.     End If
    74.    
    75.     'If Not MSFlexGrid1.Rows = Total_Results Then
    76.     '    WriteShow (Show_Name)
    77.     'End If
    78.        
    79.     FlexGridDone = True
    80.     FillGrid = True
    81.     MSFlexGrid1.Redraw = True
    82.     MSFlexGrid1.Refresh
    83.    
    84. Error:
    85.     If Err.Number = 30002 Then
    86.         MSFlexGrid1.Redraw = True
    87.         MSFlexGrid1.Refresh
    88.         FlexGridDone = True
    89.         FillGrid = True
    90.     End If
    91.         MSFlexGrid1.Redraw = True
    92.         MSFlexGrid1.Refresh
    93.         FlexGridDone = True
    94.         FillGrid = True
    95. End Function

    Still getting extra rows from somewhere.

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: MSFlexGrid Row Anomalys

    A few comments about your code.

    What is the "another bad FlexGrid Bug" you are trying to fix? Note that whatever it is is probably not the flexgrid's fault.

    Do you realize that your code "falls through" to your Error: code?

    Also do you realize the code in both parts of the If/Else in the Error: code is the same

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: MSFlexGrid Row Anomalys

    yes... the code was poorly written at this state, because I was getting no luck with fixing the errors. Like I mentioned in my first post, I seriously doubt that the errors are the controls, and more along the lines of my poor coding. I'm still getting used to the language. I'm barely an intermediate user.

    As with some more thinking and looking at the code, I lost my row 0... so the .clear statement won't work... I remember why I did that now. revising the code so I get this back... maybe completely writing that block will clear up some issues.
    Last edited by DJHotIce; Nov 8th, 2005 at 04:45 PM.

  11. #11

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: MSFlexGrid Row Anomalys

    where I remove more items that get inserted somehow... I'm trying to mask the bugs than fix them... Which I'm guessing is not a good idea?

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: MSFlexGrid Row Anomalys

    What happens if you change this

    VB Code:
    1. Counter = 1
    2.     With rs
    3.         Do Until rs.EOF = True
    4.             MSFlexGrid1.AddItem ("")
    5.             'Fill In the Col. Data.
    6.                 MSFlexGrid1.TextMatrix(Counter, 2) = !Tal
    7.                 MSFlexGrid1.TextMatrix(Counter, 3) = !Slug
    8.                 MSFlexGrid1.TextMatrix(Counter, 4) = !Format
    9.                 MSFlexGrid1.TextMatrix(Counter, 5) = !Graphics
    10.                 MSFlexGrid1.TextMatrix(Counter, 6) = !Status
    11.                 MSFlexGrid1.TextMatrix(Counter, 7) = !Tape
    12.                 MSFlexGrid1.TextMatrix(Counter, 8) = !SOT
    13.                 MSFlexGrid1.TextMatrix(Counter, 9) = !Read
    14.                 MSFlexGrid1.TextMatrix(Counter, 13) = !autonumber
    15.                 '.TextMatrix(Counter, 2) =
    16.             'Go To New Row
    17.             'Fill First Col With Data
    18.             Counter = Counter + 1
    19.             .MoveNext
    20.         Loop
    21.        
    22.     End With
    23.    
    24.    
    25.     Dim Total_Results As Integer
    26.     Total_Results = rs.RecordCount
    27.     rs.Close
    28.     cn.Close
    29.    
    30.    
    31.     'Fix for wierd cell bug
    32.     MSFlexGrid1.Row = 1
    33.     MSFlexGrid1.Col = 1
    34.     MSFlexGrid1.CellBackColor = RGB(255, 255, 255)
    35.    
    36.    
    37.     'Possibly Fix another bad FlexGrid Bug?
    38.     If MSFlexGrid1.Rows >= Total_Results + 1 Then
    39.         MSFlexGrid1.RemoveItem (MSFlexGrid1.Rows)
    40.     End If

    to this?

    VB Code:
    1. Counter = 1
    2.     With rs
    3.         Do Until .EOF
    4.             'Fill In the Col. Data.
    5.                 MSFlexGrid1.TextMatrix(Counter, 2) = !Tal
    6.                 MSFlexGrid1.TextMatrix(Counter, 3) = !Slug
    7.                 MSFlexGrid1.TextMatrix(Counter, 4) = !Format
    8.                 MSFlexGrid1.TextMatrix(Counter, 5) = !Graphics
    9.                 MSFlexGrid1.TextMatrix(Counter, 6) = !Status
    10.                 MSFlexGrid1.TextMatrix(Counter, 7) = !Tape
    11.                 MSFlexGrid1.TextMatrix(Counter, 8) = !SOT
    12.                 MSFlexGrid1.TextMatrix(Counter, 9) = !Read
    13.                 MSFlexGrid1.TextMatrix(Counter, 13) = !autonumber
    14.             Counter = Counter + 1
    15.             .MoveNext
    16.         Loop
    17.        
    18.     End With
    19.    
    20.    
    21.     Dim Total_Results As Integer
    22.     Total_Results = rs.RecordCount
    23.     rs.Close
    24.     cn.Close
    25.    
    26.    
    27.     'Fix for wierd cell bug
    28.     MSFlexGrid1.Row = 1
    29.     MSFlexGrid1.Col = 1
    30.     MSFlexGrid1.CellBackColor = RGB(255, 255, 255)

  14. #14

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Jun 2005
    Posts
    192

    Re: MSFlexGrid Row Anomalys

    Of Course AddItem will add a blank line, but then I go back in and populate it with textmatrix... thus nulling out the effect of having a blank line. Now why would it add 2 blank lines if it hasn't reached EOF? Anyways, I think I got that part of the code working... I will need to work on some other code not related to this main issue now...

    I'm going to toy with the other issue for a while longer because it is not that critical just yet... THus Marking as resolved.

  16. #16
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: MSFlexGrid Row Anomalys

    Quote Originally Posted by DJHotIce
    Of Course AddItem will add a blank line, but then I go back in and populate it with textmatrix... thus nulling out the effect of having a blank line. Now why would it add 2 blank lines if it hasn't reached EOF? Anyways, I think I got that part of the code working... I will need to work on some other code not related to this main issue now...

    I'm going to toy with the other issue for a while longer because it is not that critical just yet... THus Marking as resolved.
    No, that's not what happens. What does happen is that every time that line is executed a new blank line is written, but nothing gets written to those lines. Take a look at this example.
    Attached Images Attached Images  

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