Function Reference

_GUICtrlListBox_SetCurSel

文字列を選択し、表示されるように必要な場合はスクロールします。

#Include <GuiListBox.au3>
_GUICtrlListBox_SetCurSel($hWnd, $iIndex)

 

パラメータ

$hWnd コントロールのハンドル
$iIndex 選択される文字列のゼロ始まりのインデックスを指定します。
このパラメータが-1の場合、リストボックスの全ての選択が解除されます。

 

返し値

成功: True
失敗: False

 

注意

この関数はアイテムを1つだけ選択できるリストボックスでのみ使用できます。
複数選択できるリストボックスに対する選択の設定、解除には使用できません。

 

関連

_GUICtrlListBox_GetCurSel

 


#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>

Opt('MustDeclareVars', 1)

$Debug_LB = False ; ListBox関数に渡されるClassNameを調べる。動作を確認するにはTrueを設定し、他のコントロールのハンドルを使用

_Main()

Func _Main()
    Local $hListBox

    ; GUIを作成
    GUICreate("List Box Set Cur Sel", 400, 296)
    $hListBox = GUICtrlCreateList("", 2, 2, 396, 296)
    GUISetState()

    ; 文字列を追加
    _GUICtrlListBox_BeginUpdate($hListBox)
    For $iI = 1 To 9
        _GUICtrlListBox_AddString($hListBox, StringFormat("%03d : Random string", Random(1, 100, 1)))
    Next
    _GUICtrlListBox_EndUpdate($hListBox)

    ; アイテムを選択
    _GUICtrlListBox_SetCurSel($hListBox, 4)

    ; 現在選択されているアイテムを取得
    MsgBox(4160, "Information", "Current selction: " & _GUICtrlListBox_GetCurSel($hListBox))

    ; ユーザーが終了するまでループ
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main