AutoIt GUICtrlCreateListView Function

How to use the AutoIt GUICreateListView function to create a list with selectable items.

1914 views

Edited: 2019-01-10 17:16

The AutoIt GUICtrlCreateListView function is used to create a list with selectable items in AutoIt GUIs.

Parameters

textRequiredThe text of the column headings, separated by pipe "|" characters, or as specified by Opt("GUIDataSeparatorChar")
leftRequiredPosition from the left, in pixels.
topRequiredPosition from the top, in pixels.
widthOptionalThe width of the control, in pixels.
heightOptionalThe height of the control, in pixels.
styleOptionalControls the style of the window – See also: ListView Styles
ExStyleOptionalControls the extended style of the window – See also: ListView Extended Styles

Example

 #include <GUIConstantsEx.au3>
 #include <ListviewConstants.au3>
 
 Opt("GUIOnEventMode", 1)

MainGUI()

 ; ----- GUIs
Func MainGUI()
  Global $listview
  $listGUI = GUICreate("AutoIt GUICtrlCreateListView Example", 400, 200, 100, 200, -1)
  GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose")
  $listview = GUICtrlCreateListView("Username|Password", 10, 10, 200, 150, $LVS_NOSORTHEADER+$LVS_SINGLESEL,$LVS_EX_GRIDLINES)

  GUICtrlCreateListViewItem("John|1234", $listview)
  GUICtrlCreateListViewItem("AutoItUser|153_4", $listview)

  $BtnSelect = GUICtrlCreateButton("Select", 100, 165, 80, 30)
  GUICtrlSetOnEvent(-1, "SelectItem")

  GUISetState()
  
  While 1
    Sleep(10)
  WEnd
EndFunc
 ; ///// Functions
Func SelectItem()
  $sItem = GUICtrlRead(GUICtrlRead($listview))
  $sItem = StringTrimRight($sItem, 1) ; Will remove the pipe "|" from the end of the string
  MsgBox(0, "Selected Item", $sItem)
EndFunc
  
Func OnClose()
   Exit
EndFunc

Tell us what you think:

  1. How to create a list of selectable items with AutoIt.
  2. Tutorial on how to make GUIs using the AutoIt scripting language.
  3. How to disable and enable AutoIt GUI elements using GUICtrlSetState.
  4. How to interrupt running functions and handle system events in AutoIt GUI scripting.
  5. Tutorial on how to add images to AutoIt GUIs while maintaining aspect ratio.

More in: AutoIt GUIs