Clearstructure in MSHFlexgrid

Grifter
01-10-2005, 03:43 PM
OK guys....i am using a butchered version of FlyGuy's function to view a flexgrid.....however....once i change record i need the grid to clear itself of the data and leave headers....

I used to used the mygrd.CLEARSTRUCTURE command but that is for some reason unavailable to me now.....i have tried the .Clear but this does not work...

any suggestions???

posting code just in case...


Private Sub fillgrid()
Dim adoConn As ADODB.Connection
Dim adoRST As ADODB.Recordset

On Error GoTo errHandler

' open the connection
Set adoConn = New ADODB.Connection
adoConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\cadetdb.mdb" & ";" _
& " Persist Security Info=False;Jet OLEDB:Database Password=sharpe;"

current = Text5.Text

' get a recordset
Set adoRST = New ADODB.Recordset
sql = "SELECT Campname AS Campname,Startdate AS 'Start Date',Enddate AS 'End Date' ,paid " _
& "AS Paid FROM Cadet, cadetcamp, camplist WHERE cadet.cadetno = cadetcamp.cadetid " _
& "AND cadetcamp.campid = camplist.campid AND cadet.cadetno = " & current & ";"
MsgBox sql

adoRST.Open sql, adoConn, adOpenKeyset, adLockReadOnly, adCmdText

With adoRST
If Not .EOF Then
FG_ShowRecordset MSFlexGrid1, adoRST
End If
.Close
End With
adoConn.Close

Set adoConn = Nothing
Set adoRST = Nothing
Exit Sub

errHandler:
MsgBox "An error occured." & vbLf & Err.Number & ": " & Err.Description, vbCritical
Set adoConn = Nothing
Set adoRST = Nothing
End Sub

Private Sub FG_ShowRecordset(myFG As MSFlexGrid, myRST As ADODB.Recordset)
Dim iField As Integer, iNofFields As Integer
Dim lRow As Long

Screen.MousePointer = vbHourglass

With myRST
.MoveFirst
iNofFields = .Fields.Count
End With

With myFG
.Redraw = False
.AllowUserResizing = flexResizeColumns
.ScrollTrack = True
.FixedCols = 0
.FixedRows = 0
.Cols = iNofFields
.Rows = 1

' setup the header
For iField = 0 To iNofFields - 1
.TextMatrix(0, iField) = myRST.Fields(iField).Name
Next iField
End With

With myRST
Do
' increase the number of rows
lRow = myFG.Rows
myFG.Rows = myFG.Rows + 1

' add the values to the current row
For iField = 0 To iNofFields - 1
If Not IsNull(.Fields(iField).Value) Then
myFG.TextMatrix(lRow, iField) = .Fields(iField).Value
End If
Next iField

' proceed to the next record
.MoveNext
Loop Until .EOF
End With

With myFG
.FixedRows = 1
.Redraw = True
End With

Screen.MousePointer = vbNormal
End Sub

Flyguy
01-11-2005, 02:47 AM
The normal FlexGrid control doesn't have a ClearStructure method.
If I understand you correct you only want to remove the data rows and keep the fixed rows:
MSFlexGrid1.Rows = MSFlexGrid1.FixedRows

Grifter
01-11-2005, 06:30 AM
tried that...does not seem to work either...

perhaps i am placing it in to wrong place....i put it here

tried a few other places but this seemed the most possible to me

Private Sub FG_ShowRecordset(myFG As MSFlexGrid, myRST As ADODB.Recordset)
Dim iField As Integer, iNofFields As Integer
Dim lRow As Long

Screen.MousePointer = vbHourglass

With myRST
.MoveFirst
iNofFields = .Fields.Count
End With

With myFG
.Redraw = False
.AllowUserResizing = flexResizeColumns
.ScrollTrack = True
.FixedCols = 0
.FixedRows = 0
.Rows = .FixedRows '<-------------------------------------HERE
.Cols = iNofFields
.Rows = 1

' setup the header
For iField = 0 To iNofFields - 1
.TextMatrix(0, iField) = myRST.Fields(iField).Name
Next iField
End With

Flyguy
01-11-2005, 02:50 PM
In this case Rows and FixedRows should be 1.

Grifter
01-12-2005, 10:17 AM
In this case Rows and FixedRows should be 1.

Still not got it.....

i have double checked the input from the SQL and it should definately clear....

any other suggestions please flyguy??

Grifter
01-12-2005, 10:38 AM
Flyguy....no worries.....got it sorted....

did a runthru of the code and it occured to me that if the SQL returned nothing it would not get to the section of code I was inserting the statements at....

so right after the SQL runs i inserted a simple if statement...



adoRST.Open SQL, adoConn, adOpenKeyset, adLockReadOnly, adCmdText

If adoRST.RecordCount = 0 Then ' <--------------------HERE
MSFlexGrid1.Clear
MSFlexGrid1.Rows = 1
End If

With adoRST
If Not .EOF Then
FG_ShowRecordset MSFlexGrid1, adoRST
End If
.Close
End With
adoConn.Close



this does unfortunately remove the headers.....but that i can work around....thanks a bunch for your help all the same.

Flyguy
01-12-2005, 04:20 PM
Remove the .Clear :

If adoRST.RecordCount = 0 Then ' <--------------------HERE
' MSFlexGrid1.Clear
MSFlexGrid1.Rows = 1
End If

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum