Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flexgrid Row selection problem after empty flexgrid.

Status
Not open for further replies.

Keacher

Technical User
Jan 6, 2003
12
GB
I am using VB6 FE and an Access BE connecting using ado. I have a Flexgrid that is populated using a recordset. The user can enter selection criteria to retrieve data from the db. If the user enters a selection criteria that returns no results, then the no data is shown on the flexgrid, which is fine. But the next time results are returned the flexgrid starts behaving strangely. If I click on e.g row 5, the data from row 4 is displayed in text boxes I have on my form. Also the row clicked is not highlighted properly anymore. Everything works fine until an occasion when no results are returned. After that it goes all microsoft on me.

Thanks in advance for any help given.

Here is my code.

'Get Data
Set datTempRS = New Recordset
datTempRS.CursorLocation = adUseClient
datTempRS.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly

'Display in grid
Set FlexGrid.DataSource = datTempRS
 
Hope This would help you?.........
FlexMembers.Cols = 8
With FlexMembers
.ColWidth(0) = 600
.ColWidth(1) = 2200 ' name of the field
.ColWidth(2) = 2200 '
.ColWidth(3) = 2220 '
.ColWidth(4) = 2200 '
.ColWidth(5) = 2200 '
.ColWidth(6) = 2200 '
.ColWidth(7) = 2200 '


.TextMatrix(0, 0) = "field1"
.TextMatrix(0, 1) = "field2"
.TextMatrix(0, 2) = "field3"
.TextMatrix(0, 3) = "field4"
.TextMatrix(0, 4) = "field5"
.TextMatrix(0, 5) = "field5"
.TextMatrix(0, 6) = "field6"
.TextMatrix(0, 7) = "field7"

adoRecordset.Open sql, adoConnection, adOpenStatic, adLockOptimistic,adCmdText

Flex.Rows = 1
loop1 = 0

adoRecordset.MoveFirst
Do Until adoRecordset.EOF
TDM = DoEvents()
loop1 = loop1 + 1

FlexMembers.AddItem ""
For loop2 = 0 To 6
Select Case loop2

Case 0:
FlexMembers.TextMatrix(loop1, loop2) = adoRecordset!field1
Case 1:
FlexMembers.TextMatrix(loop1, loop2) = adoRecordset!field2

Case 2:
FlexMembers.TextMatrix(loop1, loop2) = adoRecordset!field3
Case 3:
FlexMembers.TextMatrix(loop1, loop2) = adoRecordset!field4
Case 4:
FlexMembers.TextMatrix(loop1, loop2) = adoRecordset!field5
Case 5:

...................
Case 7:
FlexMembers.TextMatrix(loop1, loop2)=adoRecordset
field7

End Select

Next loop2
adoRecordset.MoveNext
DoEvents
Loop
 
Thanks ABAKA. I used your idea and got round the problem using the following code. However if anyone does know how to get round the initial problem of an empty recordset messing up mshFlexgrid I would still love to know. Its just a lot easier to set the flexgrid datasource to a recordset.



Private Sub GetRecords()

Dim i As Integer
Dim x As Integer

'Get the records selected
If Trim$(txtClientName.Text) = "" Then
sSQL = "select * from tblClients"
Else
sSQL = "select * from tblClients where clientname = '" & txtClientName.Text & "'"
End If


Set datTempRS = New Recordset
datTempRS.CursorLocation = adUseClient

datTempRS.Open sSQL, dfwConn, adOpenForwardOnly, adLockReadOnly

With MSHFlexGrid1

'Initialize grid
.Clear
.Rows = 2


'Set the grid column headings
For i = 0 To datTempRS.Fields.Count - 1
.TextMatrix(0, i) = datTempRS.Fields(i).Name
Next i

'Fill in Details if records exist
If datTempRS.RecordCount > 0 Then
For i = 1 To datTempRS.RecordCount

.AddItem "", i
For x = 0 To datTempRS.Fields.Count - 1
.TextMatrix(i, x) = datTempRS.Fields(x).Value
Next x

datTempRS.MoveNext

Next i
'Get rid of the last row which will be blank
.Rows = .Rows - 1
Else
'Else If no records, then get rid of the 2nd row which will be blank
.RowHeight(1) = 0
End If

End With

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top