找回密码
 加入
搜索
查看: 826|回复: 4

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

[复制链接]
发表于 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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2022-4-2 10:01:51 | 显示全部楼层
_GUICtrlListView_SetItemSelected($idListView, -1)
替换成这个
_GUICtrlListView_SetItemSelected($idListview, -1,False,False)
 楼主| 发表于 2022-4-2 10:26:15 | 显示全部楼层
skysmile 发表于 2022-4-2 10:01
_GUICtrlListView_SetItemSelected($idListView, -1)
替换成这个
_GUICtrlListView_SetItemSelected($id ...

没想到可选参数也要加上才行,谢谢!请教一下,Listview项目允许多选,怎么设置,样式和扩展样式我都过了几遍,没有看到相关的式样。
发表于 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[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
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-12-22 16:07 , Processed in 0.074828 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表