Func CreateListView() ;创建列表
;Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)
Local $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_TRACKSELECT, $LVS_EX_SUBITEMIMAGES)
$hListView = _GUICtrlListView_Create($myGUI, "", 126, 77, 467, 325, -1, -1, True) ; 最后一个选项调用 CoIn
_GUICtrlListView_SetExtendedListViewStyle($hListView, $exStyles)
;Local $hListView = GUICtrlCreateListView("", 154, 40, 510, 406, $LVS_NOSORTHEADER, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_TRACKSELECT))
; 加载图像
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddBitmap($hImage, '.\ico.bmp')
_GUICtrlListView_SetImageList($hListView, $hImage, 1)
; 添加列
_GUICtrlListView_InsertColumn($hListView, 0, "菜名", 120)
_GUICtrlListView_InsertColumn($hListView, 1, "价格", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "菜名", 105)
_GUICtrlListView_InsertColumn($hListView, 3, "价格", 125)
; 为列表视图控件分配100项目内存
_GUICtrlListView_SetItemCount($hListView, 100)
; 添加项目
LoadListView("咸骨粥")
EndFunc ;==>CreateListView
Func LoadListView($sj) ;加载数据到列表中
; 清除所有项目
_GUICtrlListView_DeleteAllItems($hListView)
; 添加项目
Dim $myArray[100][2], $rows = 0
Dim $count = 0, $line = 0, $nums = 0
$myArray = IniReadSection(".\Food.dat", $sj)
_GUICtrlListView_BeginUpdate($hListView)
For $k = $myArray[0][0] To 1 Step -1 ;倒序添加项目,使组名正序
; 分离值
$aItems = StringSplit($myArray[$k][1], "|")
$line = Int($aItems[0] / 4)
If (Mod($aItems[0], 4) <> 0) Then $line += 1
$nums = 1
; 添加列表项目
For $j = 1 To $line
_GUICtrlListView_AddItem($hListView, $aItems[$nums])
For $p = $nums + 1 To $nums + 3
If ($p <= $aItems[0]) Then
_GUICtrlListView_AddSubItem($hListView, $rows, $aItems[$p], $p - $nums)
EndIf
Next
$rows += 1
$nums += 4
Next
; 建立组
_GUICtrlListView_EnableGroupView($hListView)
_GUICtrlListView_InsertGroup($hListView, 0, $k, $myArray[$k][0])
;MsgBox(0,"","$k="&$k &@CRLF& "Name="&$myArray[$k][0])
; 添加组项目
For $i = 0 To $line - 1
_GUICtrlListView_SetItemGroupID($hListView, $count, $k)
$count = $count + 1
Next
_GUICtrlListView_EndUpdate($hListView)
Next
EndFunc ;==>LoadListView
另外,列表头是否有美化的函数