wxcontrolwithitemsthis class is an abstract base class for some wxwidgets controls which contain several items, such as wxlistbox and wxchecklistbox derived from it, wxchoice and wxcombobox. it defines the methods for accessing the controls items and although each of the derived classes implements them differently, they still all conform to the same interface. the items in a wxcontrolwithitems have (non-empty) string labels and, optionally, client data associated with them. client data may be of two different kinds: either simple untyped (void *) pointers which are simply stored by the control but not used in any way by it, or typed pointers (wxclientdata *) which are owned by the control meaning that the typed client data (and only it) will be deleted when an item is deleted or the entire control is cleared (which also happens when it is destroyed). finally note that in the same control all items must have client data of the same type (typed or untyped), if any. this type is determined by the first call to append (the version with client data pointer) or setclientdata. derived from
wxcontrol include files <wx/ctrlsub.h> but usually never included directly members
wxcontrolwithitems::append
wxcontrolwithitems::appendint append(const wxstring& item) adds the item to the end of the list box. int append(const wxstring& item, void *clientdata) int append(const wxstring& item, wxclientdata *clientdata) adds the item to the end of the list box, associating the given, typed or untyped, client data pointer with the item. void append(const wxarraystring& strings) appends several items at once to the control. notice that calling this method may be much faster than appending the items one by one if you need to add a lot of items. parameters item
clientdata
return value when appending a single item, the return value is the index of the newly added item which may be different from the last one if the control is sorted (e.g. has wxlb_sort or wxcb_sort style).
wxcontrolwithitems::clearvoid clear() removes all items from the control. clear() also deletes the client data of the existing items if it is owned by the control.
wxcontrolwithitems::deletevoid delete(unsigned int n) deletes an item from the control. the client data associated with the item will be also deleted if it is owned by the control. note that it is an error (signalled by an assert failure in debug builds) to remove an item with the index negative or greater or equal than the number of items in the control. parameters n
see also
wxcontrolwithitems::findstringint findstring(const wxstring& string, bool casesensitive = false) finds an item whose label matches the given string. parameters string
casesensitive
return value the zero-based position of the item, or wxnot_found if the string was not found.
wxcontrolwithitems::getclientdatavoid * getclientdata(unsigned int n) const returns a pointer to the client data associated with the given item (if any). it is an error to call this function for a control which doesn't have untyped client data at all although it is ok to call it even if the given item doesn't have any client data associated with it (but other items do). parameters n
return value a pointer to the client data, or null if not present.
wxcontrolwithitems::getclientobjectwxclientdata * getclientobject(unsigned int n) const returns a pointer to the client data associated with the given item (if any). it is an error to call this function for a control which doesn't have typed client data at all although it is ok to call it even if the given item doesn't have any client data associated with it (but other items do). parameters n
return value a pointer to the client data, or null if not present.
wxcontrolwithitems::getcountunsigned int getcount() const returns the number of items in the control. see also
wxcontrolwithitems::getselectionint getselection() const returns the index of the selected item or wxnot_found if no item is selected. return value the position of the current selection. remarks this method can be used with single selection list boxes only, you should use wxlistbox::getselections for the list boxes with wxlb_multiple style. see also setselection, getstringselection
wxcontrolwithitems::getstringwxstring getstring(unsigned int n) const returns the label of the item with the given index. parameters n
return value the label of the item or an empty string if the position was invalid.
wxcontrolwithitems::getstringswxarraystring getstrings() const returns the array of the labels of all items in the control.
wxcontrolwithitems::getstringselectionwxstring getstringselection() const returns the label of the selected item or an empty string if no item is selected. see also
wxcontrolwithitems::insertint insert(const wxstring& item, unsigned int pos) inserts the item into the list before pos. not valid for wxlb_sort or wxcb_sort styles, use append instead. int insert(const wxstring& item, unsigned int pos, void *clientdata) int insert(const wxstring& item, unsigned int pos, wxclientdata *clientdata) inserts the item into the list before pos, associating the given, typed or untyped, client data pointer with the item. not valid for wxlb_sort or wxcb_sort styles, use append instead. parameters item
pos
clientdata
return value the return value is the index of the newly inserted item. if the insertion failed for some reason, -1 is returned.
wxcontrolwithitems::isemptybool isempty() const returns true if the control is empty or false if it has some items. see also
wxcontrolwithitems::numberint number() const obsolescence note: this method is obsolete and was replaced with getcount, please use the new method in the new code. this method is only available if wxwidgets was compiled with wxwin_compatibility_2_2 defined and will disappear completely in future versions.
wxcontrolwithitems::selectvoid select(int n) this is the same as setselection and exists only because it is slightly more natural for controls which support multiple selection.
wxcontrolwithitems::setclientdatavoid setclientdata(unsigned int n, void *data) associates the given untyped client data pointer with the given item. note that it is an error to call this function if any typed client data pointers had been associated with the control items before. parameters n
data
wxcontrolwithitems::setclientobjectvoid setclientobject(unsigned int n, wxclientdata *data) associates the given typed client data pointer with the given item: the data object will be deleted when the item is deleted (either explicitly by using deletes or implicitly when the control itself is destroyed). note that it is an error to call this function if any untyped client data pointers had been associated with the control items before. parameters n
data
wxcontrolwithitems::setselectionvoid setselection(int n) sets the selection to the given item n or removes the selection entirely if n == wxnot_found. note that this does not cause any command events to be emitted nor does it deselect any other items in the controls which support multiple selections. parameters n
see also
wxcontrolwithitems::setstringvoid setstring(unsigned int n, const wxstring& string) sets the label for the given item. parameters n
string
wxcontrolwithitems::setstringselectionbool setstringselection(const wxstring& string) selects the item with the specified string in the control. this doesn't cause any command events being emitted. parameters string
return value true if the specified string has been selected, false if it wasn't found in the control. see also
|