如何在VB中利用listview快速显示10000以上的记录 listview显示起来美观,可就是速度不行 比如下面的方式 For i = 0 To 10000 ListView1.ListItems.Add ListView1.ListItems.Count + 1, , ListView1.ListItems.Count + 1 ListView1.ListItems.Item(ListView1.ListItems.Count).SubItems(1) = ("你好啊") ListView1.ListItems.Item(ListView1.ListItems.Count).SubItems(2) = ("你好啊") ListView1.ListItems.Item(ListView1.ListItems.Count).SubItems(3) = ("你好啊") Next i 用逐个添加速度很慢,看到一个avafind软件,几万行的数据显示出来只要零点几秒 请问各位高手如何在VB中实现listview的快速显示呢?只要没有停顿感就好。 如果能解决,可再加100分 ------解决方案-------------------------------------------------------- 其实很简单,有种virtual模式就可以的啊,你可搜下相应的资料:) ------解决方案-------------------------------------------------------- 先禁止列表重绘,再添加数据 自己添加 LockWindowUpdate api,然后这样: LockWindowUpdate hWndListView for xxx。。。 给列表添加数据 next LockWindowUpdate 0& ------解决方案-------------------------------------------------------- LockWindowUpdate禁止LV控件重绘,然后开一个循环,不要加DoEvents,就直接添加全部数据,这样速度有显著提升。 ------解决方案-------------------------------------------------------- 换个思路,这么多记录,就用分页啊。 ------解决方案-------------------------------------------------------- ' 避免显示区域的闪动现象。 Call ValidateRect(cLvwMer.hwnd, rc) DoEvents p = p + 1 If p Mod 1000 = 0 Then Call InvalidateRect(cLvwMer.hwnd, rc, True) cLvwMer.Refresh Call ValidateRect(cLvwMer.hwnd, rc) End If 这样可以每1000行显示一次,2,3万行数据也就10来秒钟,基本没有停顿感 ------解决方案-------------------------------------------------------- 在显示开始前,还要加这句 '获 得listview的显示区域。 Call GetClientRect(cLvwMer.hwnd, rc) rc的定义 Public Type RECT '用来定义一个区域的坐标 Left As Long Top As Long Right As Long Bottom As Long End Type ------解决方案-------------------------------------------------------- '本程序经过VB6测试,完美实现LISTVIEW动态增加记录的功能。 'Form1 Code Option Explicit Private Sub Form_Load() Dim Index As Long ListView1.ColumnHeaders.Add , , "Column 1" ListView1.LabelEdit = lvwManual ListView1.View = lvwReport ListView2.ColumnHeaders.Add , , "Column 1" ListView2.LabelEdit = lvwManual ListView2.View = lvwReport For Index = 1 To 1000 ListView1.ListItems.Add , , "Item " & CStr(Index) ' ListView2.ListItems.Add , , "Item " & CStr(Index) Next ListViewSubClass ListView1.hwnd '子类化 'ListViewSubClass ListView2.hwnd End Sub Public Sub Add1000() '滚动条移动一次增加1000条记录 Dim Index As Long Dim I As Long I = ListView1.ListItems.Count If I < 30000 Then 'ListView1中当记录小于30000条时增加记录 For Index = I + 1 To I + 1000 ListView1.ListItems.Add , , "Item " & CStr(Index) 'ListView2.ListItems.Add , , "Item " & CStr(Index) Next End If End Sub 'Module1 Code Option Explicit Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long |
|