ListView Control은 매우 느리게로드됩니다
-
03-07-2019 - |
문제
9 개의 하위 항목이있는 15000 개가 넘는 목록이있을 때 쿼리에서 ListView를 채우는 가장 빠른 방법은 무엇입니까? 로드하는 데 약 6 분이 걸립니다.
다음은 ListView Control을 채우기 위해 쓴 내용입니다.
Set rs = db.OpenRecordset(strSQL, dbOpenForwardOnly, dbReadOnly)
With Me.listViewData
.View = lvwReport
.GridLines = True
.FullRowSelect = True
.ListItems.Clear
.ColumnHeaders.Clear
End With
'Set up column headers
With Me.listViewData.ColumnHeaders
.Add , , "Client", 1440, lvwColumnLeft
.Add , , "Contact", 2160, lvwColumnLeft
.Add , , "Quote #", 720, lvwColumnCenter
.Add , , "Date", 1140, lvwColumnLeft
.Add , , "GrandTotal", 1440, lvwColumnRight
.Add , , "Weighted Value", 1440, lvwColumnRight
.Add , , "Chance %", 500, lvwColumnRight
.Add , , "Sales Cycle", 1140, lvwColumnRight
.Add , , "Won Orders", 1000, lvwColumnRight
.Add , , "SalesRep", 1000, lvwColumnRight
End With
While Not rs.EOF
Set lstItem = Me.listViewData.ListItems.Add()
lstItem.Text = Nz(rs!Name, "")
lstItem.SubItems(1) = Nz(rs!Company, "")
lstItem.SubItems(2) = Nz(rs!QuoteNumber, "")
lstItem.SubItems(3) = Nz(rs!OrderDate, "")
lstItem.SubItems(4) = Nz(Format(rs!GrandTotal, "Currency"), "0.00")
lstItem.SubItems(5) = Nz(Format(rs!GrandTotal * rs!Customfield1 / 100, "Currency"), "")
lstItem.SubItems(6) = Nz(rs!Customfield1, "")
lstItem.SubItems(7) = Nz(rs!Date1, "none")
lstItem.SubItems(8) = Nz(rs!Detail, "")
lstItem.SubItems(9) = Nz(rs!CustomT1, Nz(rs!UserID, ""))
For I = 1 To Me.listViewData.ColumnHeaders.Count - 1
Set sb = lstItem.ListSubItems(I)
If rs!Customfield1 = 100 Or Not IsNull(rs!List) Then
sb.ForeColor = vbBlue
lstItem.ForeColor = vbBlue
ElseIf rs!Cancelled = -1 Then
sb.ForeColor = vbRed
lstItem.ForeColor = vbRed
Else
sb.ForeColor = vbBlack
lstItem.ForeColor = vbBlack
End If
DoEvents
Next
rs.MoveNext
Wend
해결책 2
나는 몇 가지를 생각할 수 있습니다.
... Wend는 느린 루핑 메커니즘입니다. 다음에 사용합니다. 다음은 레코드 카운트를 얻기 위해 다른 명령을 실행 해야하는 경우에도 더 빠릅니다. 이것이 제가 사용하는 것입니다.
With rs
If .RecordCount > 0 Then
'-- MoveLast...MoveFirst will update the .RecordCount; depending on the type of DAO Recordset, RecordCount might only return "1" when there are more than that.
.MoveLast
.MoveFirst
For lngCounter = 1 To .RecordCount
'-- Code to add ListItems here
.MoveNext
Next lngCounter
End If
.Close
End With
하위 항목을 추가하려면 다음과 함께 사용하십시오.
With Me.listViewData.ListItems.Add
.Text = Nz(rs!Name, "")
.SubItems(1) = Nz(rs!Company, "")
.SubItems(2) = Nz(rs!QuoteNumber, "")
.SubItems(3) = Nz(rs!OrderDate, "")
.SubItems(4) = Nz(Format(rs!GrandTotal, "Currency"), "0.00")
.SubItems(5) = Nz(Format(rs!GrandTotal * rs!Customfield1 / 100, "Currency"), "")
.SubItems(6) = Nz(rs!Customfield1, "")
.SubItems(7) = Nz(rs!Date1, "none")
.SubItems(8) = Nz(rs!Detail, "")
.SubItems(9) = Nz(rs!CustomT1, Nz(rs!UserID, ""))
End With
포퓰레이터 코드를 다음에 랩핑하십시오.
DoCmd.Echo False
'-- Populate code
DoCmd.Echo True
도움이되기를 바랍니다!
다른 팁
첫 번째는 당신이해야 할 일은 실제 공연 살인자 인 "Dovents"를 제거하는 것입니다.
ListView를 동적으로로드해야합니까? 왜 데이터 소스에 직접 묶지 않습니까?
ListView Control의 방법을 BeginUpdate / EndUpdate와 같은 것에 대해 확인하거나 가능한 경우 새로 고침을 설정하십시오 (가능하면). 즉, 각 항목이 추가 된 후 UI가 화면을 새로 고치지 않으려 고하여 추가가 훨씬 빠릅니다.
ListView 컨트롤은 많은 수의 항목을 사용하도록 설계되었으므로 약간의 파기로 가능해야합니다.
제휴하지 않습니다 StackOverflow