This 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.
<wx/ctrlsub.h> but usually never included directly
Adds the item to the end of the list box.
Adds the item to the end of the list box, associating the given, typed or untyped, client data pointer with the item.
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.
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).
Removes all items from the control.
Clear() also deletes the client data of the existing items if it is owned by the control.
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.
Finds an item whose label matches the given string.
The zero-based position of the item, or wxNOT_FOUND if the string was not found.
void * GetClientData(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).
A pointer to the client data, or NULL if not present.
wxClientData * GetClientObject(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).
A pointer to the client data, or NULL if not present.
int GetCount(void) const
Returns the number of items in the control.
int GetSelection(void) const
Returns the index of the selected item or wxNOT_FOUND if no item is selected.
The position of the current selection.
This method can be used with single selection list boxes only, you should use wxListBox::GetSelections for the list boxes with wxLB_MULTIPLE style.
wxString GetString(int n) const
Returns the label of the item with the given index.
The label of the item or an empty string if the position was invalid.
wxString GetStringSelection(void) const
Returns the label of the selected item or an empty string if no item is selected.
Inserts the item into the list before pos. Not valid for wxLB_SORT or wxCB_SORT styles, use Append instead.
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.
The return value is the index of the newly inserted item. If the insertion failed for some reason, -1 is returned.
bool IsEmpty(void) const
Returns true if the control is empty or false if it has some items.
int Number(void) 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.
This is the same as SetSelection and exists only because it is slightly more natural for controls which support multiple selection.
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.
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.
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.
Sets the label for the given item.
Selects the item with the specified string in the control. This doesn't cause any command events being emitted.
TRUEif the specified string has been selected, FALSEif it wasn't found in the control.