#include <GuiListView.au3>
#include <GUIConstants.au3>
$Form1 = GUICreate("ListView相关示例", 350, 350, 192, 114)
$List1 = GUICtrlCreateListView("Name|Sex|IDNumber", 16, 16, 305, 279, $LVS_ICON, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT));<==创建带图标和CheckBox的ListView
Dim $B_DESCENDING[_GUICtrlListView_GetColumnCount($List1)] ;<==定义排序数组,必不可少
_GUICtrlListView_SetColumnWidth($List1, 0, 160) ;<==设置List1第一列标题宽度
_GUICtrlListView_SetColumnWidth($List1, 1, 80) ;<==设置List1第一列标题宽度
_GUICtrlListView_SetColumnWidth($List1, 2, 80) ;<==设置List1第一列标题宽度
_AddList1Items();<==添加List1的Items
$Button1 = GUICtrlCreateButton("删除", 48, 312, 81, 25, 0)
$Button2 = GUICtrlCreateButton("恢复", 190, 314, 81, 25, 0)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit ;<==退出
Case $Button1
_DelList1Items();<==删除List1里所有的Items
Case $Button2
_AddList1Items();<==添加/刷新List1里的Items
Case $List1
_GUICtrlListView_SimpleSort($List1, $B_DESCENDING, GUICtrlGetState($List1)) ;<==List1的排序
EndSwitch
WEnd
Func _DelList1Items() ;<==删除List1里所有的Items函数
GUICtrlSendMsg($List1, $LVM_DeleteALLITEMS, 0, 0)
EndFunc
Func _AddList1Items() ;<==添加List1里的Items函数
For $i = 0 to 9
If Round($i / 2) = $i / 2 Then ;<==如果$i是2的倍数就...
$item = GUICtrlCreateListViewItem("Angus"&$i&"|Male|"&"123456", $List1)
GUICtrlSetBkColor($item, 0x800080);<==设置Item的背景颜色
GUICtrlSetImage($item, "shell32.dll", 22);<==设置图标
GUICtrlSetColor($item, 0x000000);<==设置Item项里字体颜色
GUICtrlSetState($item, $GUI_CHECKED);<==设置CheckBox为选中
Else ;<==如果$i不是2的倍数就...
$item = GUICtrlCreateListViewItem("May"&$i&"|Female|"&"654321", $List1)
GUICtrlSetBkColor($item, 0x008080);<==设置Item的背景颜色
GUICtrlSetImage($item, "shell32.dll", 20);<==设置图标
GUICtrlSetColor($item, 0xFFFFFF);<==设置Item项里字体颜色
EndIf
Next
EndFunc
Func _AllDisable() ;<==List1里的CheckBox全选
EndFunc
Func _AllEnable();<==List1里的CheckBox全不选
EndFunc
Func _SelectedCount() ;<==统计List1里CheckBox里选中了几项
EndFunc
Func _SelectedInfo();<==返回List1里CheckBox里选中项的详细信息
EndFunc
|