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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading ListView Problem

Status
Not open for further replies.

Jefftopia

Programmer
Jul 30, 2002
104
US
I have a ListView control which is being loaded on form load procedure. I also provide a command button on the form whose purpose is to refresh the ListView control. This refresh button calls on the same code which is used to load the ListView on form load.

The ListView loads beautifully on form load but not when the refresh button is used (which as I said before calls on the same code which was used in form load?). When the refresh button is clicked it adds a bunch of blank lines at the top of the ListView control and then only some of the actual data below.

I did a Ctrl+Break and walked through the code. The code formats the grid as it should and begins looping through a recordset adding items to the ListView. After it gets through the tenth record, instead of adding the next record, it adds a blank line at the top of the ListView? Not sure why it is doing this. The recordset shows that data is there. It goes through the loop as though it is adding the data but then a blank row is added at the top. It does this for the remaining records.

Here is the code being called on both form load and refresh click event:

Private Sub LoadListView()

'Clear listview.
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Clear

'Format ListView.
With ListView1
With .ColumnHeaders
.Add , "CompID", "CompID", 0, lvwColumnLeft
.Add , "Type", "Type", 650, lvwColumnLeft
.Add , "Vehicle", "Vehicle", 700, lvwColumnCenter
.Add , "Issuer", "Issuer", 3240, lvwColumnLeft
.Add , "Facility", "Facility", 1400, lvwColumnLeft
.Add , "Amount", "$ Amount", 1300, lvwColumnRight
.Add , "Price", "Price", 900, lvwColumnRight
.Add , "Analyst", "Analyst", 800, lvwColumnCenter
.Add , "Time", "Response Time", 2100, lvwColumnLeft
.Add , "TimeVal", "TimeVal", 0, lvwColumnLeft
End With

.View = lvwReport

' Open a recordset
MySQL = "SELECT tblCompRQST.Comp_id, [tblCompRQST]![deal-code] AS Vehicle, tblCompRQST.custom, " & _
"tblCompRQST.borrow_nbr, tblCompRQST.WU_id, tblCompRQST.WU_FacID, " & _
"IIf(IsNull([tblCompRQST]![custom]),UCase([tblWriteUp]![WU_Borrower]), " & _
"[Pilfile]![borrow_name]) AS Issuer, IIf(IsNull([tblCompRQST]![custom]), " & _
"[tblCapStruct]![FacDesc],[Pilfile]![loan_desc]) AS Facility, tblCompRQST.Analyst, " & _
"tblCompRQST.Price, tblCompRQST.Amount, tblCompRQST.Response_time, tblCompRQST.Status, " & _
"tblCompRQST.Type, tblCompRQST.Settled " & _
"FROM (((((tblCompRQST LEFT JOIN tblWriteUp ON tblCompRQST.WU_id = tblWriteUp.WU_id) " & _
"LEFT JOIN tblCapStruct ON tblCompRQST.WU_FacID = tblCapStruct.WU_FacID) LEFT JOIN " & _
"Pilfile ON tblCompRQST.borrow_nbr = Pilfile.borrow_nbr) LEFT JOIN tblMoodyCLOindustry ON " & _
"Pilfile.moody_code = tblMoodyCLOindustry.SSBIndustryCode) LEFT JOIN tblSPCLOindustry ON " & _
"Pilfile.sp_code = tblSPCLOindustry.SPIndustryCode) LEFT JOIN tblFIndustry ON " & _
"tblCompRQST.FIndustryCode = tblFIndustry.FIndustryCode " & _
"GROUP BY tblCompRQST.Comp_id, [tblCompRQST]![deal-code], tblCompRQST.custom, " & _
"tblCompRQST.borrow_nbr, tblCompRQST.WU_id, tblCompRQST.WU_FacID, " & _
"IIf(IsNull([tblCompRQST]![custom]),UCase([tblWriteUp]![WU_Borrower]), " & _
"[Pilfile]![borrow_name]), IIf(IsNull([tblCompRQST]![custom]),[tblCapStruct]![FacDesc], " & _
"[Pilfile]![loan_desc]), tblCompRQST.Analyst, tblCompRQST.Price, tblCompRQST.Amount, " & _
"tblCompRQST.Response_time, tblCompRQST.Status, tblCompRQST.Type, tblCompRQST.Settled " & _
"Having (((tblCompRQST.Status)='ACCEPTED') AND ((tblCompRQST.Settled)=No));"


Set MyDb = OpenDatabase(RDSDATA_PATH & "rdstables.mdb")
Set MySet = MyDb.OpenRecordset(MySQL)

'Execute code if MySet is not empty.
If MySet.RecordCount <> 0 Then

'Moves to the first record in the recordset.
MySet.MoveFirst

' Use values from recordset to populate listview control
'****THIS IS WHERE PROBLEM OCCURS****
For I = 1 To MySet.RecordCount
.ListItems.Add I, , MySet.Fields(&quot;Comp_id&quot;)
With .ListItems(I).ListSubItems
.Add , , MySet.Fields(&quot;Type&quot;)
.Add , , MySet.Fields(&quot;Vehicle&quot;)
.Add , , MySet.Fields(&quot;Issuer&quot;)
.Add , , MySet.Fields(&quot;Facility&quot;)
.Add , , Format(MySet.Fields(&quot;Amount&quot;), &quot;#,###.00&quot;)
.Add , , Format(MySet.Fields(&quot;Price&quot;), &quot;###.0000&quot;)
.Add , , MySet.Fields(&quot;Analyst&quot;)
.Add , , MySet.Fields(&quot;Response_time&quot;)
.Add , , Format(MySet.Fields(&quot;Response_time&quot;), &quot;yyyymmddhhmmss&quot;)
End With
MySet.MoveNext
Next I
'***********************************

End If

End With

MySet.Close
MyDb.Close
Set MySet = Nothing
Set MyDb = Nothing

'Set Sort Optiot button to Ascending (A-Z).
Option2(0).Value = True
lblSelectA.Caption = &quot;0&quot;

End Sub
 
***RESOLVED***

Simply set the Sort property of the ListView = False and then set = True when finished.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top