By using this site you agree to the use of cookies by Brugbart and our partners.

Learn more

AutoIt GUICtrlCreateListViewItem Function

This AutoIt reference shows how to use the GUICtrlCreateListViewItem to insert items into a listview control.

Edited: 2015-01-15 22:07

The AutoIt GUICtrlCreateListViewItem function is used to create items in a ListView control. To create an item in a control, you will have to specify the text of the item to be created, and the listviewID in the second parameter.

See also: Creating a list with selectable items

Parameters

textRequiredThe text value of the item – if multiple columns, separated by pipe "|" characters, or the character specified by Opt("GUIDataSeparatorChar")
listviewIDOptionalThe text of the window to activate.

GUICtrlCreateListViewItem Example

The below example shows both how to create a listview control, and how to insert items into the list – you may also want to follow the AutoIt tutorial mentioned earlier.

 #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)

  ; -   -    -    -    -    -    -    -    -    -   -
  ; In this section we insert list items
  GUICtrlCreateListViewItem("John|1234", $listview)
  GUICtrlCreateListViewItem("AutoItUser|153_4", $listview)
  GUICtrlCreateListViewItem("BlueBoden|782dF", $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