Nov 8th, 2005, 03:44 PM
#1
Thread Starter
Addicted Member
[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:
Private Function WriteShow(pShow As String)
Debug.Print "Writing Show"
On Error GoTo Error
If Selection = Show_Name Then
'TreeView.SelectedItem.Next
'TreeView.SelectedItem.Next
'TreeView.SelectedItem.Next
Selection = Show_Name & ".Rundown"
End If
FlexGridDone = False
Dim Counter As Integer
Dim Counter2 As Integer 'For Refresing of FlexGrid
Dim Total As Integer
'Remove All Items Cept The First Top Item!
Counter2 = 2
Total = MSFlexGrid1.Rows
'Remove all items?
If Total >= 1 Then
Do Until Counter2 = MSFlexGrid1.Rows
MSFlexGrid1.RemoveItem (Counter2)
Counter2 = Counter2 + 1
Loop
End If
'Act Normal
cn.Open
SQL = "SELECT * FROM `Rundown` WHERE `Show` = '" & Show_Name & "' ORDER BY `Pos` ASC"
rs.Open SQL, cn, adOpenForwardOnly, adLockOptimistic
Counter2 = 0
'MSFlexGrid1.RemoveItem
Counter = 1
With rs
Do Until rs.EOF = True
MSFlexGrid1.AddItem ("")
'Fill In the Col. Data.
MSFlexGrid1.TextMatrix(Counter, 2) = !Tal
MSFlexGrid1.TextMatrix(Counter, 3) = !Slug
MSFlexGrid1.TextMatrix(Counter, 4) = !Format
MSFlexGrid1.TextMatrix(Counter, 5) = !Graphics
MSFlexGrid1.TextMatrix(Counter, 6) = !Status
MSFlexGrid1.TextMatrix(Counter, 7) = !Tape
MSFlexGrid1.TextMatrix(Counter, 8) = !SOT
MSFlexGrid1.TextMatrix(Counter, 9) = !Read
MSFlexGrid1.TextMatrix(Counter, 13) = !autonumber
'.TextMatrix(Counter, 2) =
'Go To New Row
'Fill First Col With Data
Counter = Counter + 1
.MoveNext
Loop
End With
Dim Total_Results As Integer
Total_Results = Counter - 1
rs.Close
cn.Close
'Fix for wierd cell bug
MSFlexGrid1.Row = 1
MSFlexGrid1.Col = 1
MSFlexGrid1.CellBackColor = RGB(255, 255, 255)
'Possibly Fix another bad FlexGrid Bug?
If MSFlexGrid1.Rows >= Total_Results Then
MSFlexGrid1.RemoveItem (MSFlexGrid1.Rows)
End If
If Not MSFlexGrid1.Rows = Total_Results Then
WriteShow (Show_Name)
MSFlexGrid1.Redraw = True
MSFlexGrid1.Refresh
End If
'Fix another flexgrid bug we've developed!
'Remove all rows w/o Identifer
'Dim Counter3 As Integer
'Counter3 = 2
'Do Until Counter3 = MSFlexGrid1.Cols
' If MSFlexGrid1.TextMatrix(Counter3, 13) = "" Then
'' MSFlexGrid1.RemoveItem (MSFlexGrid1.Row)
' End If
' ' Counter3 = Counter3 + 1
'Loop
FlexGridDone = True
FillGrid = True
MSFlexGrid1.Redraw = True
MSFlexGrid1.Refresh
Error:
If Err.Number = 30002 Then
MSFlexGrid1.Redraw = True
MSFlexGrid1.Refresh
FlexGridDone = True
FillGrid = True
End If
MSFlexGrid1.Redraw = True
MSFlexGrid1.Refresh
FlexGridDone = True
FillGrid = True
'Debug.Print "Another FlexGrid Error " & Err.Number & " " & Err.Description
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!
Nov 8th, 2005, 03:50 PM
#2
Hyperactive Member
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
Nov 8th, 2005, 03:52 PM
#3
Thread Starter
Addicted Member
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
Nov 8th, 2005, 03:56 PM
#4
Hyperactive Member
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.
Nov 8th, 2005, 04:04 PM
#5
Thread Starter
Addicted Member
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.
Nov 8th, 2005, 04:10 PM
#6
Re: MSFlexGrid Row Anomalys
Is it your aim to remove all the data from the grid? If so then just use MSFlexGrid1.Clear
Nov 8th, 2005, 04:21 PM
#7
Thread Starter
Addicted Member
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 .
Nov 8th, 2005, 04:24 PM
#8
Thread Starter
Addicted Member
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:
Private Function WriteShow(pShow As String)
Debug.Print "Writing Show"
On Error GoTo Error
If Selection = Show_Name Then
Selection = Show_Name & ".Rundown"
End If
FlexGridDone = False
Dim Counter As Integer
Dim Counter2 As Integer 'For Refresing of FlexGrid
Dim Total As Integer
Counter2 = 2
Total = MSFlexGrid1.Rows
'Remove All Items Cept The First Top Item!
MSFlexGrid1.Clear
'Act Normal
cn.Open
SQL = "SELECT * FROM `Rundown` WHERE `Show` = '" & Show_Name & "' ORDER BY `Pos` ASC"
rs.Open SQL, cn, adOpenForwardOnly, adLockOptimistic
Counter2 = 0
'MSFlexGrid1.RemoveItem
Counter = 1
With rs
Do Until rs.EOF = True
MSFlexGrid1.AddItem ("")
'Fill In the Col. Data.
MSFlexGrid1.TextMatrix(Counter, 2) = !Tal
MSFlexGrid1.TextMatrix(Counter, 3) = !Slug
MSFlexGrid1.TextMatrix(Counter, 4) = !Format
MSFlexGrid1.TextMatrix(Counter, 5) = !Graphics
MSFlexGrid1.TextMatrix(Counter, 6) = !Status
MSFlexGrid1.TextMatrix(Counter, 7) = !Tape
MSFlexGrid1.TextMatrix(Counter, 8) = !SOT
MSFlexGrid1.TextMatrix(Counter, 9) = !Read
MSFlexGrid1.TextMatrix(Counter, 13) = !autonumber
'.TextMatrix(Counter, 2) =
'Go To New Row
'Fill First Col With Data
Counter = Counter + 1
.MoveNext
Loop
End With
Dim Total_Results As Integer
Total_Results = rs.RecordCount
rs.Close
cn.Close
'Fix for wierd cell bug
MSFlexGrid1.Row = 1
MSFlexGrid1.Col = 1
MSFlexGrid1.CellBackColor = RGB(255, 255, 255)
'Possibly Fix another bad FlexGrid Bug?
If MSFlexGrid1.Rows >= Total_Results + 1 Then
MSFlexGrid1.RemoveItem (MSFlexGrid1.Rows)
End If
'If Not MSFlexGrid1.Rows = Total_Results Then
' WriteShow (Show_Name)
'End If
FlexGridDone = True
FillGrid = True
MSFlexGrid1.Redraw = True
MSFlexGrid1.Refresh
Error:
If Err.Number = 30002 Then
MSFlexGrid1.Redraw = True
MSFlexGrid1.Refresh
FlexGridDone = True
FillGrid = True
End If
MSFlexGrid1.Redraw = True
MSFlexGrid1.Refresh
FlexGridDone = True
FillGrid = True
End Function
Still getting extra rows from somewhere.
Nov 8th, 2005, 04:33 PM
#9
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
Nov 8th, 2005, 04:39 PM
#10
Thread Starter
Addicted Member
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 .
Nov 8th, 2005, 04:40 PM
#11
Re: MSFlexGrid Row Anomalys
OK, but what is the "another bad FlexGrid Bug"?
Nov 8th, 2005, 04:51 PM
#12
Thread Starter
Addicted Member
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?
Nov 8th, 2005, 05:05 PM
#13
Re: MSFlexGrid Row Anomalys
What happens if you change this
VB Code:
Counter = 1
With rs
Do Until rs.EOF = True
MSFlexGrid1.AddItem ("")
'Fill In the Col. Data.
MSFlexGrid1.TextMatrix(Counter, 2) = !Tal
MSFlexGrid1.TextMatrix(Counter, 3) = !Slug
MSFlexGrid1.TextMatrix(Counter, 4) = !Format
MSFlexGrid1.TextMatrix(Counter, 5) = !Graphics
MSFlexGrid1.TextMatrix(Counter, 6) = !Status
MSFlexGrid1.TextMatrix(Counter, 7) = !Tape
MSFlexGrid1.TextMatrix(Counter, 8) = !SOT
MSFlexGrid1.TextMatrix(Counter, 9) = !Read
MSFlexGrid1.TextMatrix(Counter, 13) = !autonumber
'.TextMatrix(Counter, 2) =
'Go To New Row
'Fill First Col With Data
Counter = Counter + 1
.MoveNext
Loop
End With
Dim Total_Results As Integer
Total_Results = rs.RecordCount
rs.Close
cn.Close
'Fix for wierd cell bug
MSFlexGrid1.Row = 1
MSFlexGrid1.Col = 1
MSFlexGrid1.CellBackColor = RGB(255, 255, 255)
'Possibly Fix another bad FlexGrid Bug?
If MSFlexGrid1.Rows >= Total_Results + 1 Then
MSFlexGrid1.RemoveItem (MSFlexGrid1.Rows)
End If
to this?
VB Code:
Counter = 1
With rs
Do Until .EOF
'Fill In the Col. Data.
MSFlexGrid1.TextMatrix(Counter, 2) = !Tal
MSFlexGrid1.TextMatrix(Counter, 3) = !Slug
MSFlexGrid1.TextMatrix(Counter, 4) = !Format
MSFlexGrid1.TextMatrix(Counter, 5) = !Graphics
MSFlexGrid1.TextMatrix(Counter, 6) = !Status
MSFlexGrid1.TextMatrix(Counter, 7) = !Tape
MSFlexGrid1.TextMatrix(Counter, 8) = !SOT
MSFlexGrid1.TextMatrix(Counter, 9) = !Read
MSFlexGrid1.TextMatrix(Counter, 13) = !autonumber
Counter = Counter + 1
.MoveNext
Loop
End With
Dim Total_Results As Integer
Total_Results = rs.RecordCount
rs.Close
cn.Close
'Fix for wierd cell bug
MSFlexGrid1.Row = 1
MSFlexGrid1.Col = 1
MSFlexGrid1.CellBackColor = RGB(255, 255, 255)
Nov 8th, 2005, 05:09 PM
#14
Re: MSFlexGrid Row Anomalys
BTW I think your problem is this line
which doesn't do anything except add blank lines at the end of the grid.
Nov 8th, 2005, 05:22 PM
#15
Thread Starter
Addicted Member
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.
Nov 8th, 2005, 06:01 PM
#16
Re: MSFlexGrid Row Anomalys
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
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width