smooth 发表于 2022-4-1 23:28:49

[已解决]列表视图无法取消所有选中项目

本帖最后由 smooth 于 2022-4-7 15:50 编辑

根据帮助,把Listview的样式设置为$LVS_SINGLESEL,然后_GUICtrlListView_SetItemSelected($idListView, -1)就可以取消所有选择的项目,可是不知道为啥,试了没有作用。


#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
Local $idListview
GUICreate("ListView Set Item Selected", 400, 300)
$idListview = GUICtrlCreateListView("", 2, 2, 394, 268, $LVS_SINGLESEL)
GUISetState(@SW_SHOW)
; Add columns
_GUICtrlListView_AddColumn($idListview, "Items", 100)
; Add items
_GUICtrlListView_AddItem($idListview, "Item 1")
_GUICtrlListView_AddItem($idListview, "Item 2")
_GUICtrlListView_AddItem($idListview, "Item 3")
; Select item 2

_GUICtrlListView_SetItemSelected($idListview, 1)

_GUICtrlListView_SetItemSelected($idListView, -1)

;~MsgBox(0, "Information", "Item 2 Selected: " & _GUICtrlListView_GetItemSelected($idListview, 1))
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc   ;==>Example


skysmile 发表于 2022-4-2 10:01:51

_GUICtrlListView_SetItemSelected($idListView, -1)
替换成这个
_GUICtrlListView_SetItemSelected($idListview, -1,False,False)

afan 发表于 2022-4-2 10:17:54

理解反了。

smooth 发表于 2022-4-2 10:26:15

skysmile 发表于 2022-4-2 10:01
_GUICtrlListView_SetItemSelected($idListView, -1)
替换成这个
_GUICtrlListView_SetItemSelected($id ...

没想到可选参数也要加上才行,谢谢!请教一下,Listview项目允许多选,怎么设置,样式和扩展样式我都过了几遍,没有看到相关的式样。

yohoboy 发表于 2022-4-4 23:35:19

範例如下

#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,$j = 1
        $totalnum = _GUICtrlListView_GetItemCount($ListView1)
        $selectcount = _GUICtrlListView_GetSelectedCount($ListView1)
        $val = $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
页: [1]
查看完整版本: [已解决]列表视图无法取消所有选中项目