Contents Up Previous Next

wxListCtrl

A list control presents lists in a number of formats: list view, report view, icon view and small icon view. Elements are numbered from zero.

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

Derived from

wxControl
wxWindow
wxEvtHandler
wxObject

Include files

<wx/listctrl.h>

Window styles

wxLC_LIST multicolumn list view, with optional small icons. Columns are computed automatically, i.e. you don't set columns as in wxLC_REPORT. In other words, the list wraps, unlike a wxListBox.
wxLC_REPORT single or multicolumn report view, with optional header.
wxLC_ICON Large icon view, with optional labels.
wxLC_SMALL_ICON Small icon view, with optional labels.
wxLC_ALIGN_TOP Icons align to the top (default).
wxLC_ALIGN_LEFT Icons align to the left.
wxLC_AUTOARRANGE Icons arrange themselves.
wxLC_USER_TEXT The application provides label text on demand, except for column headers.
wxLC_EDIT_LABELS Labels are editable: the application will be notified when editing starts.
wxLC_NO_HEADER No header in report mode.
wxLC_SINGLE_SEL Single selection.
wxLC_SORT_ASCENDING Sort in ascending order (must still supply a comparison callback in SortItems.
wxLC_SORT_DESCENDING Sort in descending order (must still supply a comparison callback in SortItems.

See also window styles overview.

Event handling

To process input from a list control, use these event handler macros to direct input to member functions that take a wxListEvent argument.

EVT_LIST_BEGIN_DRAG(id, func) Begin dragging with the left mouse button.
EVT_LIST_BEGIN_RDRAG(id, func) Begin dragging with the right mouse button.
EVT_LIST_BEGIN_LABEL_EDIT(id, func) Begin editing a label.
EVT_LIST_END_LABEL_EDIT(id, func) Finish editing a label.
EVT_LIST_DELETE_ITEM(id, func) Delete an item.
EVT_LIST_DELETE_ALL_ITEMS(id, func) Delete all items.
EVT_LIST_GET_INFO(id, func) Request information from the application, usually the item text.
EVT_LIST_SET_INFO(id, func) Information is being supplied (not implemented).
EVT_LIST_ITEM_SELECTED(id, func) The item has been selected.
EVT_LIST_ITEM_DESELECTED(id, func) The item has been deselected.
EVT_LIST_KEY_DOWN(id, func) A key has been pressed.
EVT_LIST_INSERT_ITEM(id, func) An item has been inserted.
EVT_LIST_COL_CLICK(id, func) A column (m_col) has been left-clicked.
See also

wxListCtrl overview, wxListBox, wxTreeCtrl, wxImageList, wxListEvent

Members

wxListCtrl::wxListCtrl
wxListCtrl::~wxListCtrl
wxListCtrl::Arrange
wxListCtrl::Create
wxListCtrl::DeleteItem
wxListCtrl::DeleteAllItems
wxListCtrl::DeleteColumn
wxListCtrl::Edit
wxListCtrl::EnsureVisible
wxListCtrl::FindItem
wxListCtrl::GetColumn
wxListCtrl::GetColumnWidth
wxListCtrl::GetCountPerPage
wxListCtrl::GetEditControl
wxListCtrl::GetImageList
wxListCtrl::GetItem
wxListCtrl::GetItemData
wxListCtrl::GetItemPosition
wxListCtrl::GetItemRect
wxListCtrl::GetItemState
wxListCtrl::GetItemCount
wxListCtrl::GetItemSpacing
wxListCtrl::GetItemText
wxListCtrl::GetNextItem
wxListCtrl::GetSelectedItemCount
wxListCtrl::GetTextColour
wxListCtrl::GetTopItem
wxListCtrl::HitTest
wxListCtrl::InsertColumn
wxListCtrl::InsertItem
wxListCtrl::ScrollList
wxListCtrl::SetBackgroundColour
wxListCtrl::SetColumn
wxListCtrl::SetColumnWidth
wxListCtrl::SetImageList
wxListCtrl::SetItem
wxListCtrl::SetItemData
wxListCtrl::SetItemImage
wxListCtrl::SetItemPosition
wxListCtrl::SetItemState
wxListCtrl::SetItemText
wxListCtrl::SetSingleStyle
wxListCtrl::SetTextColour
wxListCtrl::SetWindowStyleFlag
wxListCtrl::SortItems


wxListCtrl::wxListCtrl

wxListCtrl()

Default constructor.

wxListCtrl(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listCtrl")

Constructor, creating and showing a list control.

Parameters

parent

id

pos

size

style

validator

name

See also

wxListCtrl::Create, wxValidator


wxListCtrl::~wxListCtrl

void ~wxListCtrl()

Destructor, destroying the list control.


wxListCtrl::Arrange

bool Arrange(int flag = wxLIST_ALIGN_DEFAULT)

Arranges the items in icon or small icon view. flag is one of:

wxLIST_ALIGN_DEFAULT Default alignment.
wxLIST_ALIGN_LEFT Align to the left side of the control.
wxLIST_ALIGN_TOP Align to the top side of the control.
wxLIST_ALIGN_SNAP_TO_GRID Snap to grid.


wxListCtrl::Create

bool Create(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxLC_ICON, const wxValidator& validator = wxDefaultValidator, const wxString& name = "listCtrl")

Creates the list control. See wxListCtrl::wxListCtrl for further details.


wxListCtrl::DeleteItem

bool DeleteItem(long item)

Deletes the specified item.


wxListCtrl::DeleteAllItems

bool DeleteAllItems()

Deletes all the items in the list control.


wxListCtrl::DeleteColumn

bool DeleteColumn(int col)

Deletes a column.


wxListCtrl::Edit

wxTextCtrl& Edit(long item)

Starts editing a label.


wxListCtrl::EnsureVisible

bool EnsureVisible(long item)

Ensures this item is visible.


wxListCtrl::FindItem

long FindItem(long start, const wxString& str, const bool partial = FALSE)

Find an item whose label matches this string, starting from the item after start or the beginning if start is -1.

long FindItem(long start, long data)

Find an item whose data matches this data, starting from the item after start or the beginning if 'start' is -1.

long FindItem(long start, const wxPoint& pt, int direction)

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

wxPython note:
In place of a single overloaded method name, wxPython implements the following methods:


wxListCtrl::GetColumn

bool GetColumn(int col, wxListItem& item) const

Gets information about this column. See wxListCtrl::SetItem for more information.


wxListCtrl::GetColumnWidth

int GetColumnWidth(int col) const

Gets the column width (report view only).


wxListCtrl::GetCountPerPage

int GetCountPerPage() const

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


wxListCtrl::GetEditControl

wxTextCtrl& GetEditControl() const

Gets the edit control for editing labels.


wxListCtrl::GetImageList

wxImageList* GetImageList(int which) const

Returns the specified image list. which may be one of:

wxIMAGE_LIST_NORMAL The normal (large icon) image list.
wxIMAGE_LIST_SMALL The small icon image list.
wxIMAGE_LIST_STATE The user-defined state image list (unimplemented).


wxListCtrl::GetItem

bool GetItem(wxListItem& info) const

Gets information about the item. See wxListCtrl::SetItem for more information.

wxPython note:
The wxPython version of this method takes a parameter representing the item ID, and returns the wxListItem object.


wxListCtrl::GetItemData

long GetItemData(long item) const

Gets the application-defined data associated with this item.


wxListCtrl::GetItemPosition

bool GetItemPosition(long item, wxPoint& pos) const

Returns the position of the item, in icon or small icon view.

wxPython note:
The wxPython version of this method accempts only the item ID and returns the wxPoint.


wxListCtrl::GetItemRect

bool GetItemRect(long item, wxRect& rect, int code = wxLIST_RECT_BOUNDS) const

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

code is one of wxLIST_RECT_BOUNDS, wxLIST_RECT_ICON, wxLIST_RECT_LABEL.

wxPython note:
The wxPython version of this method accempts only the item ID and returns the wxRect.


wxListCtrl::GetItemState

int GetItemState(long item, long stateMask) const

Gets the item state. For a list of state flags, see wxListCtrl::SetItem.

The stateMask indicates which state flags are of interest.


wxListCtrl::GetItemCount

int GetItemCount() const

Returns the number of items in the list control.


wxListCtrl::GetItemSpacing

int GetItemSpacing(bool isSmall) const

Retrieves the spacing between icons in pixels. If small is TRUE, gets the spacing for the small icon view, otherwise the large icon view.


wxListCtrl::GetItemText

wxString GetItemText(long item) const

Gets the item text for this item.


wxListCtrl::GetNextItem

long GetNextItem(long item, int geometry = wxLIST_NEXT_ALL, int state = wxLIST_STATE_DONTCARE) const

Searches for an item with the given goemetry or state, starting from item. item can be -1 to find the first item that matches the specified flags.

Returns the item or -1 if unsuccessful.

geometry can be one of:

wxLIST_NEXT_ABOVE Searches for an item above the specified item.
wxLIST_NEXT_ALL Searches for subsequent item by index.
wxLIST_NEXT_BELOW Searches for an item below the specified item.
wxLIST_NEXT_LEFT Searches for an item to the left of the specified item.
wxLIST_NEXT_RIGHT Searches for an item to the right of the specified item.

state can be a bitlist of the following:

wxLIST_STATE_DONTCARE Don't care what the state is.
wxLIST_STATE_DROPHILITED The item indicates it is a drop target.
wxLIST_STATE_FOCUSED The item has the focus.
wxLIST_STATE_SELECTED The item is selected.
wxLIST_STATE_CUT The item is selected as part of a cut and paste operation.


wxListCtrl::GetSelectedItemCount

int GetSelectedItemCount() const

Returns the number of selected items in the list control.


wxListCtrl::GetTextColour

wxColour GetTextColour() const

Gets the text colour of the list control.


wxListCtrl::GetTopItem

long GetTopItem() const

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


wxListCtrl::HitTest

long HitTest(const wxPoint& point, int& flags)

Determines which item (if any) is at the specified point, giving details in flags. flags will be a combination of the following flags:

wxLIST_HITTEST_ABOVE Above the client area.
wxLIST_HITTEST_BELOW Below the client area.
wxLIST_HITTEST_NOWHERE In the client area but below the last item.
wxLIST_HITTEST_ONITEMICON On the bitmap associated with an item.
wxLIST_HITTEST_ONITEMLABEL On the label (string) associated with an item.
wxLIST_HITTEST_ONITEMRIGHT In the area to the right of an item.
wxLIST_HITTEST_ONITEMSTATEICON On the state icon for a tree view item that is in a user-defined state.
wxLIST_HITTEST_TOLEFT To the right of the client area.
wxLIST_HITTEST_TORIGHT To the left of the client area.
wxLIST_HITTEST_ONITEM Combination of wxLIST_HITTEST_ONITEMICON, wxLIST_HITTEST_ONITEMLABEL, wxLIST_HITTEST_ONITEMSTATEICON.


wxListCtrl::InsertColumn

long InsertColumn(long col, wxListItem& info)

For list view mode (only), inserts a column. For more details, see wxListCtrl::SetItem.

long InsertColumn(long col, const wxString& heading, int format = wxLIST_FORMAT_LEFT, int width = -1)

For list view mode (only), inserts a column. For more details, see wxListCtrl::SetItem.

wxPython note:
In place of a single overloaded method name, wxPython implements the following methods:


wxListCtrl::InsertItem

long InsertItem(wxListItem& info)

Inserts an item, returning the index of the new item if successful, -1 otherwise.

long InsertItem(long index, const wxString& label)

Inserts a string item.

long InsertItem(long index, int imageIndex)

Inserts an image item.

long InsertItem(long index, const wxString& label, int imageIndex)

Insert an image/string item.

Parameters

info

index

label

imageIndex

wxPython note:
In place of a single overloaded method name, wxPython implements the following methods:


wxListCtrl::ScrollList

bool ScrollList(int dx, int dy)

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.

If in icon, small icon or list view mode, dy specifies the number of pixels to scroll. If in report view mode, dy specifies the number of lines to scroll.


wxListCtrl::SetBackgroundColour

void SetBackgroundColour(const wxColour& col)

Sets the background colour (GetBackgroundColour already implicit in wxWindow class).


wxListCtrl::SetColumn

bool SetColumn(int col, wxListItem& item)

Sets information about this column. See wxListCtrl::SetItem for more information.


wxListCtrl::SetColumnWidth

bool SetColumnWidth(int col, int width)

Sets the column width.

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

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


wxListCtrl::SetImageList

void SetImageList(wxImageList* imageList, int which)

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


wxListCtrl::SetItem

bool SetItem(wxListItem& info)

Sets information about the item.

wxListItem is a class with the following members:

long m_mask Indicates which fields are valid. See the list of valid mask flags below.
long m_itemId The zero-based item position.
int m_col Zero-based column, if in report mode.
long m_state The state of the item. See the list of valid state flags below.
long m_stateMask A mask indicating which state flags are valid. See the list of valid state flags below.
wxString m_text The label/header text.
int m_image The zero-based index into an image list.
long m_data Application-defined data.
int m_format For columns only: the format. Can be wxLIST_FORMAT_LEFT, wxLIST_FORMAT_RIGHT or wxLIST_FORMAT_CENTRE.
int m_width For columns only: the column width.

The m_mask member contains a bitlist specifying which of the other fields are valid. The flags are:

wxLIST_MASK_STATE The m_state field is valid.
wxLIST_MASK_TEXT The m_text field is valid.
wxLIST_MASK_IMAGE The m_image field is valid.
wxLIST_MASK_DATA The m_data field is valid.
wxLIST_MASK_WIDTH The m_width field is valid.
wxLIST_MASK_FORMAT The m_format field is valid.

The m_stateMask and m_state members take flags from the following:

wxLIST_STATE_DONTCARE Don't care what the state is.
wxLIST_STATE_DROPHILITED The item is highlighted to receive a drop event.
wxLIST_STATE_FOCUSED The item has the focus.
wxLIST_STATE_SELECTED The item is selected.
wxLIST_STATE_CUT The item is in the cut state.

long SetItem(long index, int col, const wxString& label, int imageId = -1)

Sets a string field at a particular column.

wxPython note:
In place of a single overloaded method name, wxPython implements the following methods:


wxListCtrl::SetItemData

bool SetItemData(long item, long data)

Associates application-defined data with this item.


wxListCtrl::SetItemImage

bool SetItemImage(long item, int image, int selImage)

Sets the unselected and selected images associated with the item. The images are indices into the image list associated with the list control.


wxListCtrl::SetItemPosition

bool SetItemPosition(long item, const wxPoint& pos)

Sets the position of the item, in icon or small icon view.


wxListCtrl::SetItemState

bool SetItemState(long item, long state, long stateMask)

Sets the item state. For a list of state flags, see wxListCtrl::SetItem.

The stateMask indicates which state flags are valid.


wxListCtrl::SetItemText

void SetItemText(long item, const wxString& text)

Sets the item text for this item.


wxListCtrl::SetSingleStyle

void SetSingleStyle(long style, const bool add = TRUE)

Adds or removes a single window style.


wxListCtrl::SetTextColour

void SetTextColour(const wxColour& col)

Sets the text colour of the list control.


wxListCtrl::SetWindowStyleFlag

void SetWindowStyleFlag(long style)

Sets the whole window style.


wxListCtrl::SortItems

bool SortItems(wxListCtrlCompare fn, long data)

Sorts the items in the list control.

fn is a function which takes 3 long arguments: item1, item2, data.

item1 is the long data associated with a first item (NOT the index).

item2 is the long data associated with a second item (NOT the index).

data is the same value as passed to SortItems.

The return value is a negative number if the first item should precede the second item, a positive number of the second item should precede the first, or zero if the two items are equivalent.

data is arbitrary data to be passed to the sort function.