# wxListCtrl Class Reference
[Controls]

`#include </home/work/projects/wx/2.9/wx/interface/wx/listctrl.h>`

Inheritance diagram for wxListCtrl:
[legend]

## Detailed Description

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 wxListCtrl::InsertItem 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 to have controls with millions of items without consuming much memory. To use virtual list control you must use wxListCtrl::SetItemCount first and override at least wxListCtrl::OnGetItemText (and optionally wxListCtrl::OnGetItemImage or wxListCtrl::OnGetItemColumnImage and wxListCtrl::OnGetItemAttr) 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.

## Styles

This class supports the following 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_VIRTUAL:
  The application provides items text on demand. May only be used with `wxLC_REPORT`.
- 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. Win32 default, Win32 only.
- wxLC_ALIGN_LEFT:
  Icons align to the left.
- wxLC_AUTOARRANGE:
  Icons arrange themselves. Win32 only.
- 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 (default is multiple).
- wxLC_SORT_ASCENDING:
  Sort in ascending order. (You must still supply a comparison callback in wxListCtrl::SortItems.)
- wxLC_SORT_DESCENDING:
  Sort in descending order. (You must still supply a comparison callback in wxListCtrl::SortItems.)
- wxLC_HRULES:
  Draws light horizontal rules between rows in report mode.
- wxLC_VRULES:
  Draws light vertical rules between columns in report mode.

## Events emitted by this class

The following event handler macros redirect the events to member function handlers 'func' with prototypes like:

void handlerFuncName(wxListEvent& event)

Event macros for events emitted by this class:

- EVT_LIST_BEGIN_DRAG(id, func):
  Begin dragging with the left mouse button. Processes a `wxEVT_COMMAND_LIST_BEGIN_DRAG` event type.
- EVT_LIST_BEGIN_RDRAG(id, func):
  Begin dragging with the right mouse button. Processes a `wxEVT_COMMAND_LIST_BEGIN_RDRAG` event type.
- EVT_BEGIN_LABEL_EDIT(id, func):
  Begin editing a label. This can be prevented by calling Veto(). Processes a `wxEVT_COMMAND_LIST_BEGIN_LABEL_EDIT` event type.
- EVT_LIST_END_LABEL_EDIT(id, func):
  Finish editing a label. This can be prevented by calling Veto(). Processes a `wxEVT_COMMAND_LIST_END_LABEL_EDIT` event type.
- EVT_LIST_DELETE_ITEM(id, func):
  An item was deleted. Processes a `wxEVT_COMMAND_LIST_DELETE_ITEM` event type.
- EVT_LIST_DELETE_ALL_ITEMS(id, func):
  All items were deleted. Processes a `wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS` event type.
- EVT_LIST_ITEM_SELECTED(id, func):
  The item has been selected. Processes a `wxEVT_COMMAND_LIST_ITEM_SELECTED` event type.
- EVT_LIST_ITEM_DESELECTED(id, func):
  The item has been deselected. Processes a `wxEVT_COMMAND_LIST_ITEM_DESELECTED` event type.
- EVT_LIST_ITEM_ACTIVATED(id, func):
  The item has been activated (ENTER or double click). Processes a `wxEVT_COMMAND_LIST_ITEM_ACTIVATED` event type.
- EVT_LIST_ITEM_FOCUSED(id, func):
  The currently focused item has changed. Processes a `wxEVT_COMMAND_LIST_ITEM_FOCUSED` event type.
- EVT_LIST_ITEM_MIDDLE_CLICK(id, func):
  The middle mouse button has been clicked on an item. This is only supported by the generic control. Processes a `wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK` event type.
- EVT_LIST_ITEM_RIGHT_CLICK(id, func):
  The right mouse button has been clicked on an item. Processes a `wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK` event type.
- EVT_LIST_KEY_DOWN(id, func):
  A key has been pressed. Processes a `wxEVT_COMMAND_LIST_KEY_DOWN` event type.
- EVT_LIST_INSERT_ITEM(id, func):
  An item has been inserted. Processes a `wxEVT_COMMAND_LIST_INSERT_ITEM` event type.
- EVT_LIST_COL_CLICK(id, func):
  A column (m_col) has been left-clicked. Processes a `wxEVT_COMMAND_LIST_COL_CLICK` event type.
- EVT_LIST_COL_RIGHT_CLICK(id, func):
  A column (m_col) has been right-clicked. Processes a `wxEVT_COMMAND_LIST_COL_RIGHT_CLICK` event type.
- EVT_LIST_COL_BEGIN_DRAG(id, func):
  The user started resizing a column - can be vetoed. Processes a `wxEVT_COMMAND_LIST_COL_BEGIN_DRAG` event type.
- EVT_LIST_COL_DRAGGING(id, func):
  The divider between columns is being dragged. Processes a `wxEVT_COMMAND_LIST_COL_DRAGGING` event type.
- EVT_LIST_COL_END_DRAG(id, func):
  A column has been resized by the user. Processes a `wxEVT_COMMAND_LIST_COL_END_DRAG` event type.
- EVT_LIST_CACHE_HINT(id, func):
  Prepare cache for a virtual list control. Processes a `wxEVT_COMMAND_LIST_CACHE_HINT` event type.

##

Library: wxCore
Category: Controls
Appearance:

wxMSW appearance | wxGTK appearance | wxMac appearance

See also:
  wxListCtrl Overview, wxListView, wxListBox, wxTreeCtrl, wxImageList, wxListEvent, wxListItem, wxEditableListBox

## Public Member Functions

| 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=wxListCtrlNameStr)
| Constructor, creating and showing a list control.
virtual | ~wxListCtrl ()
| Destructor, destroying the list control.
bool | Arrange (int flag=wxLIST_ALIGN_DEFAULT)
| Arranges the items in icon or small icon view.
void | AssignImageList (wxImageList *imageList, int which)
| Sets the image list associated with the control and takes ownership of it (i.e.
void | ClearAll ()
| Deletes all items and all columns.
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=wxListCtrlNameStr)
| Creates the list control.
bool | DeleteAllItems ()
| Deletes all items in the list control.
bool | DeleteColumn (int col)
| Deletes a column.
bool | DeleteItem (long item)
| Deletes the specified item.
wxTextCtrl * | EditLabel (long item, wxClassInfo *textControlClass=wxCLASSINFO(wxTextCtrl))
| Starts editing the label of the given item.
bool | EndEditLabel (bool cancel)
| Finish editing the label.
bool | EnsureVisible (long item)
| Ensures this item is visible.
long | FindItem (long start, const wxString &str, bool partial=false)
| Find an item whose label matches this string, starting from start or the beginning if start is `-1`.
long | FindItem (long start, wxUIntPtr data)
| Find an item whose data matches this data, starting from 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 start or the beginning if start is -1.
bool | GetColumn (int col, wxListItem &item) const
| Gets information about this column.
int | GetColumnCount () const
| Returns the number of columns.
int | GetColumnIndexFromOrder (int pos) const
| Gets the column index from its position in visual order.
int | GetColumnOrder (int col) const
| Gets the column visual order position.
int | GetColumnWidth (int col) const
| Gets the column width (report view only).
wxArrayInt | GetColumnsOrder () const
| Returns the array containing the orders of all columns.
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).
wxTextCtrl * | GetEditControl () const
| Returns the edit control being currently used to edit a label.
wxImageList * | GetImageList (int which) const
| Returns the specified image list.
bool | GetItem (wxListItem &info) const
| Gets information about the item.
wxColour | GetItemBackgroundColour (long item) const
| Returns the colour for this item.
int | GetItemCount () const
| Returns the number of items in the list control.
wxUIntPtr | GetItemData (long item) const
| Gets the application-defined data associated with this item.
wxFont | GetItemFont (long item) const
| Returns the item's font.
bool | GetItemPosition (long item, wxPoint &pos) const
| Returns the position of the item, in icon or small icon view.
bool | GetItemRect (long item, wxRect &rect, int code=wxLIST_RECT_BOUNDS) const
| Returns the rectangle representing the item's size and position, in physical coordinates.
wxSize | GetItemSpacing () const
| Retrieves the spacing between icons in pixels: horizontal spacing is returned as `x` component of the wxSize object and the vertical spacing as its `y` component.
int | GetItemState (long item, long stateMask) const
| Gets the item state.
wxString | GetItemText (long item, int col=0) const
| Gets the item text for this item.
wxColour | GetItemTextColour (long item) const
| Returns the colour for this item.
long | GetNextItem (long item, int geometry=wxLIST_NEXT_ALL, int state=wxLIST_STATE_DONTCARE) const
| Searches for an item with the given geometry or state, starting from item but excluding the item itself.
int | GetSelectedItemCount () const
| Returns the number of selected items in the list control.
bool | GetSubItemRect (long item, long subItem, wxRect &rect, int code=wxLIST_RECT_BOUNDS) const
| Returns the rectangle representing the size and position, in physical coordinates, of the given subitem, i.e.
wxColour | GetTextColour () const
| Gets the text colour of the list control.
long | GetTopItem () const
| Gets the index of the topmost visible item when in list or report view.
wxRect | GetViewRect () const
| Returns the rectangle taken by all items in the control.
long | HitTest (const wxPoint &point, int &flags, long *ptrSubItem=NULL) const
| Determines which item (if any) is at the specified point, giving details in flags.
long | InsertColumn (long col, wxListItem &info)
| For report view mode (only), inserts a column.
long | InsertColumn (long col, const wxString &heading, int format=wxLIST_FORMAT_LEFT, int width=-1)
| For report view mode (only), inserts a column.
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)
| Insert an string item.
long | InsertItem (long index, int imageIndex)
| Insert an image item.
long | InsertItem (long index, const wxString &label, int imageIndex)
| Insert an image/string item.
void | RefreshItem (long item)
| Redraws the given item.
void | RefreshItems (long itemFrom, long itemTo)
| Redraws the items between itemFrom and itemTo.
bool | ScrollList (int dx, int dy)
| Scrolls the list control.
virtual bool | SetBackgroundColour (const wxColour &col)
| Sets the background colour.
bool | SetColumn (int col, wxListItem &item)
| Sets information about this column.
bool | SetColumnWidth (int col, int width)
| Sets the column width.
bool | SetColumnsOrder (const wxArrayInt &orders) const
| Changes the order in which the columns are shown.
void | SetImageList (wxImageList *imageList, int which)
| Sets the image list associated with the control.
bool | SetItem (wxListItem &info)
| Sets the data of an item.
long | SetItem (long index, int column, const wxString &label, int imageId=-1)
| Sets an item string field at a particular column.
void | SetItemBackgroundColour (long item, const wxColour &col)
| Sets the background colour for this item.
bool | SetItemColumnImage (long item, long column, int image)
| Sets the image associated with the item.
void | SetItemCount (long count)
| This method can only be used with virtual list controls.
bool | SetItemData (long item, long data)
| Associates application-defined data with this item.
void | SetItemFont (long item, const wxFont &font)
| Sets the item's font.
bool | SetItemImage (long item, int image, int selImage=-1)
| Sets the unselected and selected images associated with the item.
bool | SetItemImage (long item, int image, int selImage=-1)
| Sets the unselected and selected images associated with the item.
bool | SetItemPosition (long item, const wxPoint &pos)
| Sets the position of the item, in icon or small icon view.
bool | SetItemPtrData (long item, wxUIntPtr data)
| Associates application-defined data with this item.
bool | SetItemState (long item, long state, long stateMask)
| Sets the item state.
void | SetItemText (long item, const wxString &text)
| Sets the item text for this item.
void | SetItemTextColour (long item, const wxColour &col)
| Sets the colour for this item.
void | SetSingleStyle (long style, bool add=true)
| Adds or removes a single window style.
void | SetTextColour (const wxColour &col)
| Sets the text colour of the list control.
void | SetWindowStyleFlag (long style)
| Sets the whole window style, deleting all items.
bool | SortItems (wxListCtrlCompare fnSortCallBack, wxIntPtr data)
| Call this function to sort the items in the list control.

## Protected Member Functions

virtual wxListItemAttr * | OnGetItemAttr (long item) const
| This function may be overridden in the derived class for a control with `wxLC_VIRTUAL` style.
virtual wxListItemAttr * | OnGetItemColumnAttr (long item, long column) const
| This function may be overridden in the derived class for a control with `wxLC_VIRTUAL` style.
virtual int | OnGetItemColumnImage (long item, long column) const
| Override this function in the derived class for a control with `wxLC_VIRTUAL` and `wxLC_REPORT` styles in order to specify the image index for the given line and column.
virtual int | OnGetItemImage (long item) const
| This function must be overridden in the derived class for a control with `wxLC_VIRTUAL` style having an "image list" (see SetImageList(); if the control doesn't have an image list, it is not necessary to override it).
virtual wxString | OnGetItemText (long item, long column) const
| This function must be overridden in the derived class for a control with `wxLC_VIRTUAL` style.

List of all members.

## Constructor & Destructor Documentation

wxListCtrl::wxListCtrl | ( |  | ) |

Default constructor.

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

Constructor, creating and showing a list control.

Parameters:

  | parent | Parent window. Must not be NULL.
  | id | Window identifier. The value wxID_ANY indicates a default value.
  | pos | Window position. If wxDefaultPosition is specified then a default position is chosen.
  | size | Window size. If wxDefaultSize is specified then the window is sized appropriately.
  | style | Window style. See wxListCtrl.
  | validator | Window validator.
  | name | Window name.

See also:
  Create(), wxValidator

virtual wxListCtrl::~wxListCtrl | ( |  | ) | `[virtual]`

Destructor, destroying the list control.

## Member Function Documentation

bool wxListCtrl::Arrange | ( | int | flag = `wxLIST_ALIGN_DEFAULT` | ) |

Arranges the items in icon or small icon view.

This only has effect on Win32. 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.

void wxListCtrl::AssignImageList | ( | wxImageList * | imageList,
|  | int | which |
| ) |  |  |

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

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

See also:
  SetImageList()

void wxListCtrl::ClearAll | ( |  | ) |

Deletes all items and all columns.

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

bool wxListCtrl::Create | ( | wxWindow * | parent,
|  | wxWindowID | id,
|  | const wxPoint & | pos = `wxDefaultPosition`,
|  | const wxSize & | size = `wxDefaultSize`,
|  | long | style = `wxLC_ICON`,
|  | const wxValidator & | validator = `wxDefaultValidator`,
|  | const wxString & | name = `wxListCtrlNameStr` |
| ) |  |  |

Creates the list control.

See wxListCtrl() for further details.

bool wxListCtrl::DeleteAllItems | ( |  | ) |

Deletes all items in the list control.

This function does not send the `wxEVT_COMMAND_LIST_DELETE_ITEM` event because deleting many items from the control would be too slow then (unlike wxListCtrl::DeleteItem) but it does send the special `wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS` event if the control was not empty. If it was already empty, nothing is done and no event is sent.

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

bool wxListCtrl::DeleteColumn | ( | int | col | ) |

Deletes a column.

bool wxListCtrl::DeleteItem | ( | long | item | ) |

Deletes the specified item.

This function sends the `wxEVT_COMMAND_LIST_DELETE_ITEM` event for the item being deleted.

See also:
  DeleteAllItems()

wxTextCtrl* wxListCtrl::EditLabel | ( | long | item,
|  | wxClassInfo * | textControlClass = `wxCLASSINFO(wxTextCtrl)` |
| ) |  |  |

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.

bool wxListCtrl::EndEditLabel | ( | bool | cancel | ) |

Finish editing the label.

This method allows to programmatically end editing a list control item in place. Usually it will only be called when editing is in progress, i.e. if GetEditControl() returns non-NULL. In particular, do not call it from EVT_LIST_BEGIN_LABEL_EDIT handler as the edit control is not yet fully created by then, just veto the event in this handler instead to prevent the editing from even starting.

Notice that calling this method will result in EVT_LIST_END_LABEL_EDIT event being generated.

Currently only implemented in wxMSW.

Parameters:

  | cancel | If true, discard the changes made by user, as if `Escape` key was pressed. Otherwise, accept the changes as if `Return` was pressed.

Returns:
  true if item editing wad finished or false if no item as being edited.

bool wxListCtrl::EnsureVisible | ( | long | item | ) |

Ensures this item is visible.

long wxListCtrl::FindItem | ( | long | start,
|  | const wxString & | str,
|  | bool | partial = `false` |
| ) |  |  |

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

The string comparison is case insensitive.

If partial is true then this method will look for items which begin with str.

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

long wxListCtrl::FindItem | ( | long | start,
|  | wxUIntPtr | data |
| ) |  |  |

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

wxPerl Note: In wxPerl this method is implemented as FindItemData(start, data).

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

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

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

wxPerl Note: In wxPerl this method is implemented as FindItemAtPos(start, pt, direction).

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

bool wxListCtrl::GetColumn | ( | int | col,
|  | wxListItem & | item |
| ) |  |  | const

Gets information about this column.

See SetItem() for more information.

wxPerl Note: In wxPerl this method takes only the col parameter and returns a `Wx::ListItem` (or `undef`).

int wxListCtrl::GetColumnCount | ( |  | ) | const

Returns the number of columns.

int wxListCtrl::GetColumnIndexFromOrder | ( | int | pos | ) | const

Gets the column index from its position in visual order.

After calling SetColumnsOrder(), the index returned by this function corresponds to the value of the element number pos in the array returned by GetColumnsOrder().

Please see SetColumnsOrder() documentation for an example and additional remarks about the columns ordering.

See also:
  GetColumnOrder()

int wxListCtrl::GetColumnOrder | ( | int | col | ) | const

Gets the column visual order position.

This function returns the index of the column which appears at the given visual position, e.g. calling it with col equal to 0 returns the index of the first shown column.

Please see SetColumnsOrder() documentation for an example and additional remarks about the columns ordering.

See also:
  GetColumnsOrder(), GetColumnIndexFromOrder()

wxArrayInt wxListCtrl::GetColumnsOrder | ( |  | ) | const

Returns the array containing the orders of all columns.

On error, an empty array is returned.

Please see SetColumnsOrder() documentation for an example and additional remarks about the columns ordering.

See also:
  GetColumnOrder(), GetColumnIndexFromOrder()

int wxListCtrl::GetColumnWidth | ( | int | col | ) | const

Gets the column width (report view only).

int wxListCtrl::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).

wxTextCtrl* wxListCtrl::GetEditControl | ( |  | ) | const

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 Mac OS X version.

wxImageList* wxListCtrl::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).

bool wxListCtrl::GetItem | ( | wxListItem & | info | ) | const

Gets information about the item.

See SetItem() 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.

wxPerl Note: In wxPerl this method takes as parameter the ID of the item and (optionally) the column, and returns a Wx::ListItem object.

wxColour wxListCtrl::GetItemBackgroundColour | ( | long | item | ) | const

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 also:
  GetItemTextColour()

int wxListCtrl::GetItemCount | ( |  | ) | const

Returns the number of items in the list control.

wxUIntPtr wxListCtrl::GetItemData | ( | long | item | ) | const

Gets the application-defined data associated with this item.

wxFont wxListCtrl::GetItemFont | ( | long | item | ) | const

Returns the item's font.

bool wxListCtrl::GetItemPosition | ( | long | item,
|  | wxPoint & | pos |
| ) |  |  | const

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

wxPerl Note: In wxPerl this method takes only the item parameter and returns a `Wx::Point` (or `undef`).

bool wxListCtrl::GetItemRect | ( | long | item,
|  | wxRect & | rect,
|  | int | code = `wxLIST_RECT_BOUNDS` |
| ) |  |  | const

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

code is one of wxLIST_RECT_BOUNDS, wxLIST_RECT_ICON, wxLIST_RECT_LABEL.

wxPerl Note: In wxPerl this method takes only the item and code parameters and returns a `Wx::Rect` (or `undef`).

wxSize wxListCtrl::GetItemSpacing | ( |  | ) | const

Retrieves the spacing between icons in pixels: horizontal spacing is returned as `x` component of the wxSize object and the vertical spacing as its `y` component.

int wxListCtrl::GetItemState | ( | long | item,
|  | long | stateMask |
| ) |  |  | const

Gets the item state.

For a list of state flags, see SetItem(). The stateMask indicates which state flags are of interest.

wxString wxListCtrl::GetItemText | ( | long | item,
|  | int | col = `0` |
| ) |  |  | const

Gets the item text for this item.

Parameters:

  | item | Item (zero-based) index.
  | col | Item column (zero-based) index. Column 0 is the default. This parameter is new in wxWidgets 2.9.1.

wxColour wxListCtrl::GetItemTextColour | ( | long | item | ) | const

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

long wxListCtrl::GetNextItem | ( | long | item,
|  | int | geometry = `wxLIST_NEXT_ALL`,
|  | int | state = `wxLIST_STATE_DONTCARE` |
| ) |  |  | const

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:

            long item = -1;
            for ( ;; )
            {
                item = listctrl->GetNextItem(item,
                                            wxLIST_NEXT_ALL,
                                            wxLIST_STATE_SELECTED);
                if ( item == -1 )
                    break;

                // this item is selected - do whatever is needed with it
                wxLogMessage("Item %ld is selected.", item);
            }

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.

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

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.

int wxListCtrl::GetSelectedItemCount | ( |  | ) | const

Returns the number of selected items in the list control.

bool wxListCtrl::GetSubItemRect | ( | long | item,
|  | long | subItem,
|  | wxRect & | rect,
|  | int | code = `wxLIST_RECT_BOUNDS` |
| ) |  |  | const

Returns the rectangle representing the size and position, in physical coordinates, of the given subitem, i.e.

the part of the row item in the column subItem.

This method is only meaningful when the wxListCtrl is in the report mode. If subItem parameter is equal to the special value `wxLIST_GETSUBITEMRECT_WHOLEITEM` the return value is the same as for GetItemRect().

code can be one of `wxLIST_RECT_BOUNDS`, `wxLIST_RECT_ICON` or `wxLIST_RECT_LABEL`.

Since:
  2.7.0

wxColour wxListCtrl::GetTextColour | ( |  | ) | const

Gets the text colour of the list control.

long wxListCtrl::GetTopItem | ( |  | ) | const

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

wxRect wxListCtrl::GetViewRect | ( |  | ) | const

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

long wxListCtrl::HitTest | ( | const wxPoint & | point,
|  | int & | flags,
|  | long * | ptrSubItem = `NULL` |
| ) |  |  | const

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:

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

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

wxPerl Note: In wxPerl this method only takes the point parameter and returns a 2-element list (item, flags).

long wxListCtrl::InsertColumn | ( | long | col,
|  | wxListItem & | info |
| ) |  |  |

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

For more details, see SetItem().

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

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

For more details, see SetItem().

long wxListCtrl::InsertItem | ( | wxListItem & | info | ) |

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

Parameters:

  | info | wxListItem object

long wxListCtrl::InsertItem | ( | long | index,
|  | const wxString & | label |
| ) |  |  |

Insert an string item.

Parameters:

  | index | Index of the new item, supplied by the application
  | label | String label

wxPerl Note: In wxPerl this method is implemented as InsertStringItem(index, label).

long wxListCtrl::InsertItem | ( | long | index,
|  | int | imageIndex |
| ) |  |  |

Insert an image item.

Parameters:

  | index | Index of the new item, supplied by the application
  | imageIndex | Index into the image list associated with this control and view style

wxPerl Note: In wxPerl this method is implemented as InsertImageItem(index, imageIndex).

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

Insert an image/string item.

Parameters:

  | index | Index of the new item, supplied by the application
  | label | String label
  | imageIndex | Index into the image list associated with this control and view style

wxPerl Note: In wxPerl this method is implemented as InsertImageStringItem(index, label, imageIndex).

virtual wxListItemAttr* wxListCtrl::OnGetItemAttr | ( | long | item | ) | const`[protected, virtual]`

This function may be overridden in the derived class for a control with `wxLC_VIRTUAL` style.

It should return the attribute for the specified `item` or NULL to use the default appearance parameters.

wxListCtrl will not delete the pointer or keep a reference of it. You can return the same wxListItemAttr pointer for every OnGetItemAttr() call.

The base class version always returns NULL.

See also:
  OnGetItemImage(), OnGetItemColumnImage(), OnGetItemText(), OnGetItemColumnAttr()

virtual wxListItemAttr* wxListCtrl::OnGetItemColumnAttr | ( | long | item,
|  | long | column |
| ) |  |  | const`[protected, virtual]`

This function may be overridden in the derived class for a control with `wxLC_VIRTUAL` style.

It should return the attribute for the for the specified item and column or NULL to use the default appearance parameters.

The base class version returns `OnGetItemAttr(item)`.

Note:
  Currently this function is only called under wxMSW, the other ports only support OnGetItemAttr()

See also:
  OnGetItemAttr(), OnGetItemText(), OnGetItemImage(), OnGetItemColumnImage(),

virtual int wxListCtrl::OnGetItemColumnImage | ( | long | item,
|  | long | column |
| ) |  |  | const`[protected, virtual]`

Override this function in the derived class for a control with `wxLC_VIRTUAL` and `wxLC_REPORT` styles in order to specify the image index for the given line and column.

The base class version always calls OnGetItemImage() for the first column, else it returns -1.

See also:
  OnGetItemText(), OnGetItemImage(), OnGetItemAttr(), OnGetItemColumnAttr()

virtual int wxListCtrl::OnGetItemImage | ( | long | item | ) | const`[protected, virtual]`

This function must be overridden in the derived class for a control with `wxLC_VIRTUAL` style having an "image list" (see SetImageList(); if the control doesn't have an image list, it is not necessary to override it).

It should return the index of the items image in the controls image list or -1 for no image.

In a control with `wxLC_REPORT` style, OnGetItemImage() only gets called for the first column of each line.

The base class version always returns -1.

See also:
  OnGetItemText(), OnGetItemColumnImage(), OnGetItemAttr()

virtual wxString wxListCtrl::OnGetItemText | ( | long | item,
|  | long | column |
| ) |  |  | const`[protected, virtual]`

This function must be overridden in the derived class for a control with `wxLC_VIRTUAL` style.

It should return the string containing the text of the given column for the specified `item`.

See also:
  SetItemCount(), OnGetItemImage(), OnGetItemColumnImage(), OnGetItemAttr()

void wxListCtrl::RefreshItem | ( | long | item | ) |

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 also:
  RefreshItems()

void wxListCtrl::RefreshItems | ( | long | itemFrom,
|  | long | itemTo |
| ) |  |  |

Redraws the items between itemFrom and itemTo.

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

Just as RefreshItem() this is only useful for virtual list controls.

bool wxListCtrl::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. dy always specifies the number of pixels to scroll vertically.

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

virtual bool wxListCtrl::SetBackgroundColour | ( | const wxColour & | col | ) | `[virtual]`

Sets the background colour.

Note that the wxWindow::GetBackgroundColour() function of wxWindow base class can be used to retrieve the current background colour.

Reimplemented from wxWindow.

bool wxListCtrl::SetColumn | ( | int | col,
|  | wxListItem & | item |
| ) |  |  |

Sets information about this column.

See SetItem() for more information.

bool wxListCtrl::SetColumnsOrder | ( | const wxArrayInt & | orders | ) | const

Changes the order in which the columns are shown.

By default, the columns of a list control appear on the screen in order of their indices, i.e. the column 0 appears first, the column 1 next and so on. However by using this function it is possible to arbitrarily reorder the columns visual order and the user can also rearrange the columns interactively by dragging them. In this case, the index of the column is not the same as its order and the functions GetColumnOrder() and GetColumnIndexFromOrder() should be used to translate between them. Notice that all the other functions still work with the column indices, i.e. the visual positioning of the columns on screen doesn't affect the code setting or getting their values for example.

The orders array must have the same number elements as the number of columns and contain each position exactly once. Its n-th element contains the index of the column to be shown in n-th position, so for a control with three columns passing an array with elements 2, 0 and 1 results in the third column being displayed first, the first one next and the second one last.

Example of using it:

                wxListCtrl *list = new wxListCtrl(...);
                for ( int i = 0; i < 3; i++ )
                    list->InsertColumn(i, wxString::Format("Column %d", i));

                wxArrayInt order(3);
                order[0] = 2;
                order[1] = 0;
                order[2] = 1;
                list->SetColumnsOrder(order);

                // now list->GetColumnsOrder() will return order and
                // list->GetColumnIndexFromOrder(n) will return order[n] and
                // list->GetColumnOrder() will return 1, 2 and 0 for the column 0,
                // 1 and 2 respectively

Please notice that this function makes sense for report view only and currently is only implemented in wxMSW port. To avoid explicit tests for `__WXMSW__` in your code, please use `wxHAS_LISTCTRL_COLUMN_ORDER` as this will allow it to start working under the other platforms when support for the column reordering is added there.

See also:
  GetColumnsOrder()

bool wxListCtrl::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).

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

void wxListCtrl::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).

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

See also:
  AssignImageList()

long wxListCtrl::SetItem | ( | long | index,
|  | int | column,
|  | const wxString & | label,
|  | int | imageId = `-1` |
| ) |  |  |

Sets an item string field at a particular column.

bool wxListCtrl::SetItem | ( | wxListItem & | info | ) |

Sets the data of an item.

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

void wxListCtrl::SetItemBackgroundColour | ( | long | item,
|  | const wxColour & | col |
| ) |  |  |

Sets the background colour for this item.

This function only works in report view mode. The colour can be retrieved using GetItemBackgroundColour().

bool wxListCtrl::SetItemColumnImage | ( | long | item,
|  | long | column,
|  | int | image |
| ) |  |  |

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.

void wxListCtrl::SetItemCount | ( | long | count | ) |

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) 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 Refresh() manually.

bool wxListCtrl::SetItemData | ( | long | item,
|  | long | data |
| ) |  |  |

Associates application-defined data with this item.

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

void wxListCtrl::SetItemFont | ( | long | item,
|  | const wxFont & | font |
| ) |  |  |

Sets the item's font.

bool wxListCtrl::SetItemImage | ( | long | item,
|  | int | image,
|  | int | selImage = `-1` |
| ) |  |  |

Sets the unselected and selected images associated with the item.

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

bool wxListCtrl::SetItemImage | ( | long | item,
|  | int | image,
|  | int | selImage = `-1` |
| ) |  |  |

Sets the unselected and selected images associated with the item.

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

Deprecated:
  This form is deprecated: selImage is not used; use the other SetItemImage() overload.

bool wxListCtrl::SetItemPosition | ( | long | item,
|  | const wxPoint & | pos |
| ) |  |  |

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

Windows only.

bool wxListCtrl::SetItemPtrData | ( | long | item,
|  | wxUIntPtr | data |
| ) |  |  |

Associates application-defined data with this item.

The data parameter may be either an integer or a pointer cast to the `wxUIntPtr` type which is guaranteed to be large enough to be able to contain all integer types and pointers.

Since:
  2.8.4

bool wxListCtrl::SetItemState | ( | long | item,
|  | long | state,
|  | long | stateMask |
| ) |  |  |

Sets the item state.

For a list of state flags, see SetItem(). The stateMask indicates which state flags are valid.

void wxListCtrl::SetItemText | ( | long | item,
|  | const wxString & | text |
| ) |  |  |

Sets the item text for this item.

void wxListCtrl::SetItemTextColour | ( | long | item,
|  | const wxColour & | col |
| ) |  |  |

Sets the colour for this item.

This function only works in report view. The colour can be retrieved using GetItemTextColour().

void wxListCtrl::SetSingleStyle | ( | long | style,
|  | bool | add = `true` |
| ) |  |  |

Adds or removes a single window style.

void wxListCtrl::SetTextColour | ( | const wxColour & | col | ) |

Sets the text colour of the list control.

void wxListCtrl::SetWindowStyleFlag | ( | long | style | ) | `[virtual]`

Sets the whole window style, deleting all items.

Reimplemented from wxWindow.

bool wxListCtrl::SortItems | ( | wxListCtrlCompare | fnSortCallBack,
|  | wxIntPtr | data |
| ) |  |  |

Call this function to sort the items in the list control.

Sorting is done using the specified fnSortCallBack function. This function must have the following prototype:

            int wxCALLBACK wxListCompareFunction(wxIntPtr item1, wxIntPtr item2, wxIntPtr sortData)

It is called each time when the two items must be compared and should return 0 if the items are equal, negative value if the first item is less than the second one and positive value if the first one is greater than the second one (the same convention as used by `qsort(3)`).

The parameter item1 is the client data associated with the first item (NOT the index). The parameter item2 is the client data associated with the second item (NOT the index). The parameter data is the value passed to SortItems() itself.

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.

Please see the List Control Sample for an example of using this function.

wxPerl Note: In wxPerl the comparison function must take just two parameters; however, you may use a closure to achieve an effect similar to the SortItems third parameter.

|  | [ top ]