大数据量 listview 显示 及 定位 缺变色
修改了 论坛一位高人的 listview 的函数 ,想秒 显示 10万条数据 ,然后 定位 到当前 在使用的一条 数据 ,不过变红色没有成功 ,请各位看看哈,多谢!#include <GUIConstantsEx.au3>#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Local $tText = DllStructCreate("wchar Text");建个结构,用来放listview列数据
Local $GUI, $hImage, $iITEM_COUNT = 100000
$hGUI = GUICreate("Form1", 760, 400)
$hListView = GUICtrlCreateListView("Item1|nSubItem1|nSubItem2", 2, 2, 760, 294, $LVS_SHOWSELALWAYS + $LVS_OWNERDATA, $LVS_EX_GRIDLINES + $LVS_EX_FULLROWSELECT + $LVS_EX_DOUBLEBUFFER)
;设置列宽
GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 0, 240)
GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 1, 240)
GUICtrlSendMsg($hListView, $LVM_SETCOLUMNWIDTH, 2, 240)
Global $icountSelect = 49
;创建并关联图像列表
$hImage = _GUIImageList_Create()
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 115)
_GUICtrlListView_SetImageList($hListView, $hImage, 1)
;===================================================================
$Button1 = GUICtrlCreateButton("数据1", 200, 352, 73, 33)
$Button2 = GUICtrlCreateButton("数据2", 300, 352, 73, 33)
$Button3 = GUICtrlCreateButton("定位 ", 400, 352, 73, 33)
Global $tData1[$iITEM_COUNT], $tData2[$iITEM_COUNT], $aData
For $i = 0 To $iITEM_COUNT - 1
For $j = 0 To 2
$tData1[$i][$j] = ' 数据 1 $aData [' & $i & '][' & $j & ']'
$tData2[$i][$j] = ' 数据 2 $aData [' & $i & '][' & $j & ']'
If $i = 49 Then $tData1[$i][$j] = "abc"
Next
Next
GUICtrlSendMsg($hListView, $LVM_SETITEMCOUNT, $iITEM_COUNT, 0)
;===================================================================
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
Case $Button1
Global $aData = $tData1
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
Case $Button2
Global $aData = $tData2
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
; Case $Button_n
; Global $aData = 你从数据库提取的二维数组,但要注意维度下标要大于或等于ColumnCount和itemCount
; 否则需要GUICtrlSendMsg($hListView, $LVM_SETITEMCOUNT, UBound($aData), 0)和 AddColumn
; GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
; GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
Case $Button3
$tData1[$icountSelect] =$icountSelect
$tData1[$icountSelect] = $icountSelect &"999"
Global $aData = $tData1
GUICtrlSendMsg($hListView, $LVM_ENSUREVISIBLE, 1, 0)
GUICtrlSendMsg($hListView, $LVM_REDRAWITEMS, 0, 20)
_GUICtrlListView_EnsureVisible($hListView, $icountSelect)
_GUICtrlListView_SetItemSelected($hListView,$icountSelect);设置选中
_GuiListView_SetItemColor($hListView,0xff0000)
$icountSelect +=1
EndSwitch
WEnd
GUIDelete()
Exit
;~ 改变指定 ListView 项目的字体颜色
Func _GuiListView_SetItemColor($hWnd, $Color)
$iItem = _GUICtrlListView_GetItemParam($hWnd,_GUICtrlListView_GetSelectionMark($hWnd))
Return GUICtrlSetColor($iItem, $Color)
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR, $iIDFrom, $iCode, $tInfo, $iItem, $iSubItem
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iIDFrom
Case $hListView
Switch $iCode
Case $LVN_GETDISPINFOA, $LVN_GETDISPINFOW ;$LVN_GETDISPINFOA = -150, $LVN_GETDISPINFOW = -177
If IsArray($aData) Then
$tInfo = DllStructCreate($tagNMLVDISPINFO, $ilParam)
$iItem = DllStructGetData($tInfo, "Item")
$iSubItem = DllStructGetData($tInfo, "SubItem")
If $iSubItem = 0 Then DllStructSetData($tInfo, "Image", 0)
DllStructSetData($tText, "Text", $aData[$iItem][$iSubItem]);
DllStructSetData($tInfo, "Text", DllStructGetPtr($tText));
EndIf
EndSwitch
EndSwitch
EndFunc ;==>WM_NOTIFY
页:
[1]