Function Reference


GUICtrlCreateListView

Creates a ListView control for the GUI.

GUICtrlCreateListView ( "text", left, top [, width [, height [, style = -1 [, exStyle = -1]]]] )

Parameters

text definition of columns heading. Each of them are separated with Opt("GUIDataSeparatorChar").
left The left side of the control. If -1 is used then left will be computed according to GUICoordMode.
top The top of the control. If -1 is used then top will be computed according to GUICoordMode.
width [optional] The width of the control (default is the previously used width).
height [optional] The height of the control (default is the previously used height).
style [optional] Defines the style of the control. See GUI Control Styles Appendix.
    default (-1) : $LVS_SHOWSELALWAYS, $LVS_SINGLESEL
    forced style : $LVS_REPORT
exStyle [optional] Defines the extended style of the control. See Extended Style Table or ListView Extended Style Table.
    default (-1) : $LVS_EX_FULLROWSELECT, $WS_EX_CLIENTEDGE

Return Value

Success: the identifier (controlID) of the new control.
Failure: 0.

Remarks

To add items to a ListView control use GUICtrlCreateListViewItem()

The ListView will appear by default as in the Explorer view "Details" (LVS_REPORT style is forced).
You can control initial column size by padding blanks to the column heading definition. The column can be extend during the GUICtrlCreateListViewItem() according to item size. Size of a column will be up to around 25 characters. No resizing will be done during an update by GUICtrlSetData().

To create a ListView with Icon-, SmallIcon- or List-style just use after creation:
GUICtrlSetStyle() with the styles $LVS_ICON, $LVS_LIST or $LVS_SMALLICON.

Sorting the list by clicking the column name (as in Explorer) is not currently implemented.

To have the entire line visually selected use the extended style LVS_EX_FULLROWSELECT.

To combine styles with the default style use BitOR($GUI_SS_DEFAULT_LISTVIEW, newstyle, ... ).
To use the values specified above you must #include <ListViewConstants.au3> in your script.

If you add the style $LVS_EX_CHECKBOXES to the ListView, then the borders are removed. Add the style $WS_EX_CLIENTEDGE to display the borders.


The special flag $GUI_BKCOLOR_LV_ALTERNATE can be used with Listview control to give alternate background of the ListviewItems lines.
The odd lines will get the color set by GUICtrlSetBkColor() of the Listview control.
The even lines will get the color set by GUICtrlSetBkColor() of the ListviewItem control.

Related

GUICoordMode (Option), GUICtrlCreateListViewItem, GUICtrlRegisterListViewSort, GUICtrlSetData, GUIDataSeparatorChar (Option), GUIGetMsg

Example

#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