bluecap 发表于 2017-10-1 15:03:09

请教GUICtrlCreateListView创建的列表如何设默认值?

比如程序自带的这个例子,想让它运行之后默认选择的是"item3“应该如何实现?谢谢!#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    GUICreate("listview items", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)
    GUISetBkColor(0x00E0FFFF) ; will change background color

    Local $idListview = GUICtrlCreateListView("col1|col2|col3", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING)
    Local $idButton = GUICtrlCreateButton("Value?", 75, 170, 70, 20)
    Local $idItem1 = GUICtrlCreateListViewItem("item2|col22|col23", $idListview)
    Local $idItem2 = GUICtrlCreateListViewItem("item1|col12|col13", $idListview)
    Local $idItem3 = GUICtrlCreateListViewItem("item3|col32|col33", $idListview)
    GUICtrlCreateInput("", 20, 200, 150)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping
    GUISetState(@SW_SHOW)
    GUICtrlSetData($idItem2, "ITEM1")
    GUICtrlSetData($idItem3, "||COL33")
    GUICtrlDelete($idItem1)

    ; Loop until the user exits.
    While 1
      Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $idButton
                MsgBox($MB_SYSTEMMODAL, "listview item", GUICtrlRead(GUICtrlRead($idListview)), 2)

            Case $idListview
                MsgBox($MB_SYSTEMMODAL, "listview", "clicked=" & GUICtrlGetState($idListview), 2)

      EndSwitch
    WEnd
EndFunc   ;==>Example

yamakawa 发表于 2017-10-1 16:21:52

作为新人,翻遍帮助文件是最好的进步。。#include <GuiListView.au3>
_GUICtrlListView_SetItemSelected ( $hWnd, $iIndex [, $bSelected = True [, $bFocused = False]] )

xzf680 发表于 2017-10-2 19:16:44

_GUICtrlListView_SetItemSelected($idListview, 0)

bluecap 发表于 2017-10-8 08:26:55

作为新人,翻遍帮助文件是最好的进步。。
yamakawa 发表于 2017-10-1 16:21 http://www.autoitx.com/images/common/back.gif


   谢谢!

bluecap 发表于 2017-10-8 08:27:08

回复 3# xzf680


    谢谢!
页: [1]
查看完整版本: 请教GUICtrlCreateListView创建的列表如何设默认值?