範例如下
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <array.au3>
#include <GuiListView.au3>
$Form1 = GUICreate("Form1", 402, 376, 337, 189)
$ListView1 = GUICtrlCreateListView("row1|row2|row3", 8, 8, 385, 329, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 50)
GUICtrlCreateListViewItem("a1|a2|a3", $ListView1)
GUICtrlCreateListViewItem("b1|b2|b3", $ListView1)
GUICtrlCreateListViewItem("c1|c2|c3", $ListView1)
GUICtrlCreateListViewItem("d1|d2|d3", $ListView1)
$Button1 = GUICtrlCreateButton("讀取", 8, 344, 75, 25)
$Button2 = GUICtrlCreateButton("關閉", 320, 344, 75, 25)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $Button2
Exit
Case $Button1
ListViewSelect()
EndSwitch
WEnd
Func ListViewSelect()
Dim $val[1],$j = 1
$totalnum = _GUICtrlListView_GetItemCount($ListView1)
$selectcount = _GUICtrlListView_GetSelectedCount($ListView1)
$val[0] = $selectcount
ReDim $val[$selectcount + 1]
For $i = 0 To $totalnum
If _GUICtrlListView_GetItemSelected($ListView1, $i) == True Then
$val[$j] = _GUICtrlListView_GetItemTextString($ListView1, $i)
$j += 1
EndIf
Next
_ArrayDisplay($val)
EndFunc
|