ListViewGetContent

Returns a list of items/rows from a ListView.

List := ListViewGetContent(Options, Control, WinTitle, WinText, ExcludeTitle, ExcludeText)

Parameters

Options

Type: String

Specifices what to retrieve. If blank or omitted, all the text in the ListView is retrieved. Otherwise, specify zero or more of the following words, each separated from the next with a space or tab:

Selected: Returns only the selected (highlighted) rows rather than all rows. If none, the return value is blank.

Focused: Returns only the focused row. If none, the return value is blank.

Col4: Returns only the fourth column (field) rather than all columns (replace 4 with a number of your choice).

Count: Returns a single number that is the total number of rows in the ListView.

Count Selected: Returns the number of selected (highlighted) rows.

Count Focused: Returns the row number (position) of the focused row (0 if none).

Count Col: Returns the number of columns in the control (or -1 if the count cannot be determined).

Control

Type: String, Integer or Object

The control's ClassNN, text or HWND, or an object with a Hwnd property. For details, see The Control Parameter.

WinTitle

Type: String, Integer or Object

A window title or other criteria identifying the target window. See WinTitle.

WinText

Type: String

If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if DetectHiddenText is ON.

ExcludeTitle

Type: String

Windows whose titles include this value will not be considered.

ExcludeText

Type: String

Windows whose text include this value will not be considered.

Return Value

Type: String

This function returns a list of items/rows. Within each row, each field (column) except the last will end with a tab character (`t). To access the items/rows individually, use a parsing loop as in example #1.

Error Handling

An exception is thrown on failure. Failure occurs when: 1) the target window or control does not exist; 2) a message could not be sent to the target control; 3) the process owning the ListView could not be opened, perhaps due to a lack of user permissions or because it is locked; 4) the ColN option specifies a nonexistent column.

Remarks

Some applications store their ListView text privately, which prevents their text from being retrieved. In these cases, an exception will usually not be thrown, but all the retrieved fields will be empty.

The columns in a ListView can be resized via SendMessage as shown in this example:

SendMessage(4126, 0, 80, "SysListView321", WinTitle)  ; 4126 is the message LVM_SETCOLUMNWIDTH.

In the above, 0 indicates the first column (specify 1 for the second, 2 for the third, etc.) Also, 80 is the new width. Replace 80 with -1 to autosize the column. Replace it with -2 to do the same but also take into account the header text width.

Window titles and text are case sensitive. Hidden windows are not detected unless DetectHiddenWindows has been turned on.

Related

ControlGetItems, WinGetList, Control functions

Examples

#1: Extracts the individual rows and fields out of a ListView:

List := ListViewGetContent("Selected", "SysListView321", WinTitle)
Loop Parse, List, "`n"  ; Rows are delimited by linefeeds (`n).
{
    RowNumber := A_Index
    Loop Parse, A_LoopField, A_Tab  ; Fields (columns) in each row are delimited by tabs (A_Tab).
        MsgBox "Row #" RowNumber " Col #" A_Index " is " A_LoopField
}