Functions for wxListCtrl class

A list control presents lists in a number of formats: list view, report view, icon view and small icon view. In any case, elements are numbered from zero. For all these modes, the items are stored in the control and must be added to it using insertItem/4 method.

A special case of report view quite different from the other modes of the list control is a virtual control in which the items data (including text, images and attributes) is managed by the main program and is requested by the control itself only when needed which allows having controls with millions of items without consuming much memory. To use virtual list control you must use setItemCount/2 first and override at least wxListCtrl::OnGetItemText (not implemented in wx) (and optionally wxListCtrl::OnGetItemImage (not implemented in wx) or wxListCtrl::OnGetItemColumnImage (not implemented in wx) and wxListCtrl::OnGetItemAttr (not implemented in wx)) to return the information about the items when the control requests it.

Virtual list control can be used as a normal one except that no operations which can take time proportional to the number of items in the control happen - this is required to allow having a practically infinite number of items. For example, in a multiple selection virtual list control, the selections won't be sent when many items are selected at once because this could mean iterating over all the items.

Using many of wxListCtrl features is shown in the corresponding sample.

To intercept events from a list control, use the event table macros described in wxListEvent.

wxMac Note: Starting with wxWidgets 2.8, wxListCtrl uses a native implementation for report mode, and uses a generic implementation for other modes. You can use the generic implementation for report mode as well by setting the mac.listctrl.always_use_generic system option (see wxSystemOptions) to 1.


This class supports the following styles:

Note: Under wxMSW this control uses wxSystemThemedControl (not implemented in wx) for an explorer style appearance by default since wxWidgets 3.1.0. If this is not desired, you can call wxSystemThemedControl::EnableSystemTheme (not implemented in wx) with false argument to disable this.

See: Overview listctrl, wxListView, wxListBox, wxTreeCtrl, wxImageList, wxListEvent, wxListItem, wxEditableListBox (not implemented in wx)

This class is derived (and can use functions) from: wxControl wxWindow wxEvtHandler

wxWidgets docs: wxListCtrl


Option =
    {winid, integer()} |
    {pos, {X :: integer(), Y :: integer()}} |
    {size, {W :: integer(), H :: integer()}} |
    {style, integer()} |
    {validator, wx:wx_object()} |
    {onGetItemText, function()} |
    {onGetItemAttr, function()} |
    {onGetItemColumnImage, function()}

Constructor, creating and showing a list control.

See: create/3, wxValidator (not implemented in wx)

Destructor, destroying the list control.


Option = {flag, integer()}

Arranges the items in icon or small icon view.

This only has effect on Win32. flag is one of:


Which = integer()

Sets the image list associated with the control and takes ownership of it (i.e.

the control will, unlike when using setImageList/3, delete the list when destroyed). which is one of wxIMAGE_LIST_NORMAL, wxIMAGE_LIST_SMALL, wxIMAGE_LIST_STATE (the last is unimplemented).

See: setImageList/3


Deletes all items and all columns.

Note: This sends an event of type wxEVT_LIST_DELETE_ALL_ITEMS under all platforms.


Deletes all items in the list control.

This function does not send the wxEVT_LIST_DELETE_ITEM event because deleting many items from the control would be too slow then (unlike deleteItem/2) but it does send the special wxEVT_LIST_DELETE_ALL_ITEMS event if the control was not empty. If it was already empty, nothing is done and no event is sent.

Return: true if the items were successfully deleted or if the control was already empty, false if an error occurred while deleting the items.


Item = integer()

Starts editing the label of the given item.

This function generates a EVT_LIST_BEGIN_LABEL_EDIT event which can be vetoed so that no text control will appear for in-place editing.

If the user changed the label (i.e. s/he does not press ESC or leave the text control without changes, a EVT_LIST_END_LABEL_EDIT event will be sent which can be vetoed as well.


Start = integer()
Pt = {X :: integer(), Y :: integer()}
Direction = integer()

Find an item nearest this position in the specified direction, starting from start or the beginning if start is -1.

Return: The next matching item if any or -1 (wxNOT_FOUND) otherwise.


Gets the number of items that can fit vertically in the visible area of the list control (list or report view) or the total number of items in the list control (icon or small icon view).


Returns the edit control being currently used to edit a label.

Returns NULL if no label is being edited.

Note: It is currently only implemented for wxMSW and the generic version, not for the native macOS version.

Gets information about the item.

See setItem/5 for more information.

You must call info.SetId() to set the ID of item you're interested in before calling this method, and info.SetMask() with the flags indicating what fields you need to retrieve from info.


Item = integer()

Returns the colour for this item.

If the item has no specific colour, returns an invalid colour (and not the default background control of the control itself).

See: getItemTextColour/2


Returns the number of items in the list control.


Result =
    {Res :: boolean(),
     Rect ::
         {X :: integer(),
          Y :: integer(),
          W :: integer(),
          H :: integer()}}
Item = integer()
Option = {code, integer()}

Returns the rectangle representing the item's size and position, in physical coordinates.



Retrieves the spacing between icons in pixels: horizontal spacing is returned as x component of the {Width,Height} object and the vertical spacing as its y component.


Item = StateMask = integer()

Gets the item state.

For a list of state flags, see setItem/5. The stateMask indicates which state flags are of interest.


Item = integer()

Returns the colour for this item.

If the item has no specific colour, returns an invalid colour (and not the default foreground control of the control itself as this wouldn't allow distinguishing between items having the same colour as the current control foreground and items with default colour which, hence, have always the same colour as the control).


Item = integer()
Option = {geometry, integer()} | {state, integer()}

Searches for an item with the given geometry or state, starting from item but excluding the item itself.

If item is -1, the first item that matches the specified flags will be returned. Returns the first item with given state following item or -1 if no such item found. This function may be used to find all selected items in the control like this:

geometry can be one of:

Note: this parameter is only supported by wxMSW currently and ignored on other platforms.

state can be a bitlist of the following:


Returns the number of selected items in the list control.


Gets the index of the topmost visible item when in list or report view.


Returns the rectangle taken by all items in the control.

In other words, if the controls client size were equal to the size of this rectangle, no scrollbars would be needed and no free space would be left.

Note that this function only works in the icon and small icon views, not in list or report views (this is a limitation of the native Win32 control).


Result =
    {Res :: integer(),
     Flags :: integer(),
     PtrSubItem :: integer()}
Point = {X :: integer(), Y :: integer()}

Determines which item (if any) is at the specified point, giving details in flags.

Returns index of the item or wxNOT_FOUND if no item is at the specified point.

flags will be a combination of the following flags:

If ptrSubItem is not NULL and the wxListCtrl is in the report mode the subitem (or column) number will also be provided. This feature is only available in version 2.7.0 or higher and is currently only implemented under wxMSW and requires at least comctl32.dll of version 4.70 on the host system or the value stored in ptrSubItem will be always -1. To compile this feature into wxWidgets library you need to have access to commctrl.h of version 4.70 that is provided by Microsoft.


Col = integer()
Option = {format, integer()} | {width, integer()}

For report view mode (only), inserts a column.

Insert a new column in the list control in report view mode at the given position specifying its most common attributes.

Notice that to set the image for the column you need to use insertColumn/4 overload and specify ?wxLIST_MASK_IMAGE in the item mask.

Return: The index of the inserted column or -1 if adding it failed.


Item = integer()

Redraws the given item.

This is only useful for the virtual list controls as without calling this function the displayed value of the item doesn't change even when the underlying data does change.

See: refreshItems/3


ItemFrom = ItemTo = integer()

Redraws the items between itemFrom and itemTo.

The starting item must be less than or equal to the ending one.

Just as refreshItem/2 this is only useful for virtual list controls.


Dx = Dy = integer()

Scrolls the list control.

If in icon, small icon or report view mode, dx specifies the number of pixels to scroll. If in list view mode, dx specifies the number of columns to scroll. dy always specifies the number of pixels to scroll vertically.

Note: This method is currently only implemented in the Windows version.


Col = Width = integer()

Sets the column width.

width can be a width in pixels or wxLIST_AUTOSIZE (-1) or wxLIST_AUTOSIZE_USEHEADER (-2).

wxLIST_AUTOSIZE will resize the column to the length of its longest item.

wxLIST_AUTOSIZE_USEHEADER will resize the column to the length of the header (Win32) or 80 pixels (other platforms).

In small or normal icon view, col must be -1, and the column width is set for all columns.


Which = integer()

Sets the image list associated with the control.

which is one of wxIMAGE_LIST_NORMAL, wxIMAGE_LIST_SMALL, wxIMAGE_LIST_STATE (the last is unimplemented).

This method does not take ownership of the image list, you have to delete it yourself.

See: assignImageList/3

Sets the data of an item.

Using the wxListItem's mask and state mask, you can change only selected attributes of a wxListCtrl item.

Return: true if the item was successfully updated or false if the update failed for some reason (e.g. an invalid item index).


Index = Column = integer()
Option = {imageId, integer()}

Sets an item string field at a particular column.

Return: true if the item was successfully updated or false if the update failed for some reason (e.g. an invalid item index).


Count = integer()

This method can only be used with virtual list controls.

It is used to indicate to the control the number of items it contains. After calling it, the main program should be ready to handle calls to various item callbacks (such as wxListCtrl::OnGetItemText (not implemented in wx)) for all items in the range from 0 to count.

Notice that the control is not necessarily redrawn after this call as it may be undesirable if an item which is not visible on the screen anyhow was added to or removed from a control displaying many items, if you do need to refresh the display you can just call wxWindow:refresh/2 manually.


Item = Data = integer()

Associates application-defined data with this item.

Notice that this function cannot be used to associate pointers with the control items, use SetItemPtrData() (not implemented in wx) instead.


Item = Image = integer()
Option = {selImage, integer()}

Sets the unselected and selected images associated with the item.

The images are indices into the image list associated with the list control.


Item = Column = Image = integer()

Sets the image associated with the item.

In report view, you can specify the column. The image is an index into the image list associated with the list control.


Item = State = StateMask = integer()

Sets the item state.

The stateMask is a combination of wxLIST_STATE_XXX constants described in wxListItem documentation. For each of the bits specified in stateMask, the corresponding state is set or cleared depending on whether state argument contains the same bit or not.

So to select an item you can use while to deselect it you should use

Consider using wxListView if possible to avoid dealing with this error-prone and confusing method.

Also notice that contrary to the usual rule that only user actions generate events, this method does generate wxEVT_LIST_ITEM_SELECTED event when it is used to select an item.


Style = integer()
Option = {add, boolean()}

Adds or removes a single window style.


Style = integer()

Sets the whole window style, deleting all items.


SortCallBack = fun((integer(), integer()) -> integer())

Sort the items in the list control.

Sorts the items with supplied SortCallBack fun.

SortCallBack receives the client data associated with two items to compare (NOT the the index), and should return 0 if the items are equal, a negative value if the first item is less than the second one and a positive value if the first item is greater than the second one.

Remark: Notice that the control may only be sorted on client data associated with the items, so you must use SetItemData if you want to be able to sort the items in the control.

The callback may not call other (wx) processes.