wxlistctrla 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 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 setitemcount first and overload at least ongetitemtext (and optionally ongetitemimage or ongetitemcolumnimage and 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. mac note: starting with 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 wxsystemoption to 1. derived from
wxcontrol include files <wx/listctrl.h> window styles
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.
wxlistctrl overview, wxlistview, wxlistbox, wxtreectrl, wximagelist, wxlistevent, wxlistitem members
wxlistctrl::wxlistctrl
wxlistctrl::wxlistctrlwxlistctrl() 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. parameters parent
id
pos
size
style
validator
name
see also wxlistctrl::create, wxvalidator
wxlistctrl::~wxlistctrlvoid ~wxlistctrl() destructor, destroying the list control.
wxlistctrl::arrangebool 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:
wxlistctrl::assignimagelistvoid 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
wxlistctrl::clearallvoid clearall() deletes all items and all columns.
wxlistctrl::createbool 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::wxlistctrl for further details.
wxlistctrl::deleteallitemsbool deleteallitems() deletes all items in the list control. nb: 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 deleteitem).
wxlistctrl::deletecolumnbool deletecolumn(int col) deletes a column.
wxlistctrl::deleteitembool 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
wxlistctrl::editlabelvoid editlabel(long item) 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.
wxlistctrl::ensurevisiblebool ensurevisible(long item) ensures this item is visible.
wxlistctrl::finditemlong finditem(long start, const wxstring& str, const 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. long finditem(long start, long 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. wxpython note: in place of a single overloaded method name, wxpython implements the following methods:
wxperl note: in wxperl there are three methods instead of a single overloaded method:
wxlistctrl::getcolumnbool getcolumn(int col, wxlistitem& item) const gets information about this column. see wxlistctrl::setitem for more information. wxperl note: in wxperl this method takes only the col parameter and returns a wx::listitem ( or undef ).
wxlistctrl::getcolumncountint getcolumncount() const returns the number of columns.
wxlistctrl::getcolumnwidthint getcolumnwidth(int col) const gets the column width (report view only).
wxlistctrl::getcountperpageint 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::geteditcontrolwxtextctrl * geteditcontrol() const returns the edit control being currently used to edit a label. returns null if no label is being edited. nb: it is currently only implemented for wxmsw and the generic version, not for the native mac os x version.
wxlistctrl::getimagelistwximagelist* getimagelist(int which) const returns the specified image list. which may be one of:
wxlistctrl::getitembool getitem(wxlistitem& info) const gets information about the item. see wxlistctrl::setitem for more information. you must call info.setid() to the id of item you're interested in before calling this method. wxpython note: the wxpython version of this method takes an integer parameter for the item id, an optional integer for the column number, and returns the wxlistitem object. wxperl note: in wxperl this method takes as parameter the id of the item and ( optionally ) the column, and returns a wx::listitem object.
wxlistctrl::getitembackgroundcolourwxcolour 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
wxlistctrl::getitemcountint getitemcount() const returns the number of items in the list control.
wxlistctrl::getitemdatalong getitemdata(long item) const gets the application-defined data associated with this item.
wxlistctrl::getitemfontwxfont getitemfont(long item) const returns the item's font.
wxlistctrl::getitempositionbool 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 accepts only the item id and returns the wxpoint. wxperl note: in wxperl this method takes only the item parameter and returns a wx::point ( or undef ).
wxlistctrl::getitemrectbool 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. wxpython note: the wxpython version of this method accepts only the item id and code and returns the wxrect. wxperl note: in wxperl this method takes only the item parameter and returns a wx::rect ( or undef ).
wxlistctrl::getsubitemrectbool 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 meaningfull 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. this function is new since wxwidgets version 2.7.0
wxlistctrl::getitemspacingwxsize 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.
wxlistctrl::getitemstateint 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::getitemtextwxstring getitemtext(long item) const gets the item text for this item.
wxlistctrl::getitemtextcolourwxcolour 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).
wxlistctrl::getnextitemlong 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:
nb: this parameter is only supported by wxmsw currently and ignored on other platforms. state can be a bitlist of the following:
wxlistctrl::getselecteditemcountint getselecteditemcount() const returns the number of selected items in the list control.
wxlistctrl::gettextcolourwxcolour gettextcolour() const gets the text colour of the list control.
wxlistctrl::gettopitemlong gettopitem() const gets the index of the topmost visible item when in list or report view.
wxlistctrl::getviewrectwxrect 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).
wxlistctrl::hittestlong hittest(const wxpoint& point, int& flags, long *ptrsubitem) 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:
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. wxpython note: a tuple of values is returned in the wxpython version of this method. the first value is the item id and the second is the flags value mentioned above. wxperl note: in wxperl this method only takes the point parameter and returns a 2-element list ( item, flags ).
wxlistctrl::insertcolumnlong insertcolumn(long col, wxlistitem& info) long 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 wxlistctrl::setitem. wxpython note: in place of a single overloaded method name, wxpython implements the following methods:
wxlistctrl::insertitemlong 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:
wxperl note: in wxperl there are four methods instead of a single overloaded method:
wxlistctrl::ongetitemattrvirtual wxlistitemattr * ongetitemattr(long item) const this function may be overloaded in the derived class for a control with wxlc_virtual style. it should return the attribute for the 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,
wxlistctrl::ongetitemimagevirtual int ongetitemimage(long item) const this function must be overloaded in the derived class for a control with wxlc_virtual style having an image list (if the control doesn't have an image list, it is not necessary to overload 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,
wxlistctrl::ongetitemcolumnimagevirtual int ongetitemcolumnimage(long item, long column) const overload 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,
wxlistctrl::ongetitemtextvirtual wxstring ongetitemtext(long item, long column) const this function must be overloaded 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,
wxlistctrl::refreshitemvoid 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
wxlistctrl::refreshitemsvoid 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.
wxlistctrl::scrolllistbool 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. nb: this method is currently only implemented in the windows version.
wxlistctrl::setbackgroundcolourvoid setbackgroundcolour(const wxcolour& col) sets the background colour (getbackgroundcolour already implicit in wxwindow class).
wxlistctrl::setcolumnbool setcolumn(int col, wxlistitem& item) sets information about this column. see wxlistctrl::setitem for more information.
wxlistctrl::setcolumnwidthbool 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.
wxlistctrl::setimagelistvoid 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
wxlistctrl::setitembool setitem(wxlistitem& info) long setitem(long index, int col, const wxstring& label, int imageid = -1) sets information about the item. wxlistitem is a class with the following members:
the m_mask member contains a bitlist specifying which of the other fields are valid. the flags are:
the m_statemask and m_state members take flags from the following:
the wxlistitem object can also contain item-specific colour and font information: for this you need to call one of settextcolour(), setbackgroundcolour() or setfont() functions on it passing it the colour/font to use. if the colour/font is not specified, the default list control colour/font is used. 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::setitembackgroundcolourvoid setitembackgroundcolour(long item, const wxcolour& col) sets the background colour for this item. this function only works in report view. the colour can be retrieved using getitembackgroundcolour.
wxlistctrl::setitemcountvoid 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 ongetitemtext) for all items in the range from 0 to count.
wxlistctrl::setitemdatabool 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.
wxlistctrl::setitemfontvoid setitemfont(long item, const wxfont& font) sets the item's font.
wxlistctrl::setitemimagebool setitemimage(long item, int image) sets the image associated with the item. the image is an index into the image list associated with the list control. in report view, this only sets the image for the first column. 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. this form is deprecated: selimage is not used.
wxlistctrl::setitemcolumnimagebool setitemimage(long item, long columnint 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.
wxlistctrl::setitempositionbool setitemposition(long item, const wxpoint& pos) sets the position of the item, in icon or small icon view. windows only.
wxlistctrl::setitemptrdatabool 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. this function is new since wxwidgets version 2.8.4
wxlistctrl::setitemstatebool 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::setitemtextvoid setitemtext(long item, const wxstring& text) sets the item text for this item.
wxlistctrl::setitemtextcolourvoid 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.
wxlistctrl::setsinglestylevoid setsinglestyle(long style, const bool add = true) adds or removes a single window style.
wxlistctrl::settextcolourvoid settextcolour(const wxcolour& col) sets the text colour of the list control.
wxlistctrl::setwindowstyleflagvoid setwindowstyleflag(long style) sets the whole window style, deleting all items.
wxlistctrl::sortitemsbool sortitems(wxlistctrlcompare fnsortcallback, long 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(long item1, long item2, long 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)). parameters item1
item2
data
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 listctrl sample for an example of using this function. wxpython note: wxpython uses the sortdata parameter to pass the python function to call, so it is not available for programmer use. call sortitems with a reference to a callable object that expects two parameters. 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.
|