|
-
Oct 26th, 2006, 08:30 AM
#1
Thread Starter
Fanatic Member
[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:
Public Sub ClearFLexGrid()
Dim intCount As Integer
MSFlexSummary.Clear
For intCount = 0 To MSFlexSummary.Rows - 1
MSFlexSummary.RemoveItem (intCount)
Next
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.
-
Oct 26th, 2006, 08:49 AM
#2
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...
-
Oct 26th, 2006, 08:54 AM
#3
Re: Remove Rows MSFlexGrid
 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...
-
Oct 26th, 2006, 09:12 AM
#4
Thread Starter
Fanatic Member
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:
Private Sub cmdRefresh_Click()
ClearFlexGrid
MSFlexSummary.Refresh
Form_Load
End Sub
Private Sub Form_Load()
Dim strSQL As String
Dim intTotal As Integer
Dim rsDateSummary As New ADODB.Recordset
Dim lngCol As Long
Dim lngRow As Long
Dim booOldRedraw As Boolean
Set rsDateSummary = New ADODB.Recordset
lblDate = Format(frmMainScreen.mebDate, "MMMM D,YYYY")
With MSFlexSummary
'Setup the required number of columns
.Cols = 2
.FixedCols = 0
.Font.Bold = True
.TextMatrix(0, 0) = "Sub-Service"
.TextMatrix(0, 1) = "Total"
.FontBold = False
'Turn off screen updates (much faster to fill the data)
booOldRedraw = .Redraw
.Redraw = False
strSQL = "select PROD.BEDS_NU_SERV_OCC.DATE_CAPTURED, PROD.BEDS_NU_SERV_OCC.SUB_SERVICE, " & _
"SUM (PROD.BEDS_NU_SERV_OCC.OCC) As OCC, PROD.BEDS_MAP_SUB_SERV_TO_SERV.SHEET_ORDER " & _
"from PROD.BEDS_MAP_SUB_SERV_TO_SERV, PROD.BEDS_NU_SERV_OCC " & _
"where PROD.BEDS_NU_SERV_OCC.DATE_CAPTURED = To_Date ('" & lblDate & "','MM/DD/YYYY') " & _
"and PROD.BEDS_NU_SERV_OCC.SUB_SERVICE = PROD.BEDS_MAP_SUB_SERV_TO_SERV.SUB_SERVICE (+) " & _
"group by PROD.BEDS_NU_SERV_OCC.DATE_CAPTURED, PROD.BEDS_NU_SERV_OCC.SUB_SERVICE, " & _
"PROD.BEDS_MAP_SUB_SERV_TO_SERV.SHEET_ORDER order by 1, 2"
rsDateSummary.Open strSQL, OraCon, adOpenForwardOnly, adLockReadOnly
If rsDateSummary.EOF Then
'If there is no data, only allow the required blank row, and hide it (height = 0)
.AddItem ""
.RemoveItem .FixedRows
.RowHeight(.FixedRows) = 0
Else
'We have data, add it one row at a time
lngRow = .Rows
Do While Not rsDateSummary.EOF
'Add the row (empty)
.AddItem ""
'Set the values one cell at a time
.TextMatrix(lngRow, lngCol) = rsDateSummary.Fields!SUB_SERVICE
.TextMatrix(lngRow, lngCol + 1) = rsDateSummary.Fields!OCC
intTotal = intTotal + rsDateSummary.Fields!OCC
'Increment Row Counter
lngRow = lngRow + 1
'Move to the next row of data
rsDateSummary.MoveNext
Loop
'Remove the blank row we left at the top
.RemoveItem .FixedRows
End If
'Re-enable screen updates
.Redraw = booOldRedraw
'Force redraw of grid
.Refresh
End With
lblTotal = intTotal
End Sub
Public Sub ClearFlexGrid()
Dim intCount As Integer
MSFlexSummary.Clear
MSFlexSummary.Rows = 1
MSFlexSummary.Cols = 0
End Sub
-
Oct 26th, 2006, 09:16 AM
#5
Re: Remove Rows MSFlexGrid
You have no heading row at the top?
-
Oct 26th, 2006, 09:24 AM
#6
Thread Starter
Fanatic Member
Re: Remove Rows MSFlexGrid
You have no heading row at the top?
It's there....just buried.
VB Code:
.TextMatrix(0, 0) = "Sub-Service"
.TextMatrix(0, 1) = "Total"
-
Oct 26th, 2006, 10:00 AM
#7
Thread Starter
Fanatic Member
Re: [RESOLVED] MSFlexGrid Help - Different Values/Same Procedure
The problem was that
VB Code:
Public Sub ClearFlexGrid()
Dim intCount As Integer
MSFlexSummary.Clear
MSFlexSummary.Rows = 1
MSFlexSummary.Cols = 0
End Sub
Should have read
VB Code:
Public Sub ClearFlexGrid()
Dim intCount As Integer
MSFlexSummary.Clear
MSFlexSummary.Rows = 2
MSFlexSummary.Cols = 2
End Sub
-
Oct 26th, 2006, 10:07 AM
#8
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...
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
|