Search documentation of wx

# wxControlWithItems (wx v2.5.4)

Copy Markdown View Source

This is convenience class that derives from both `wxControl` and `wxItemContainer` (not implemented in wx).

It is used as basis for some wxWidgets controls (`wxChoice` and `wxListBox`).

This class is derived, and can use functions, from:

- `wxControl`

- `wxWindow`

- `wxEvtHandler`

wxWidgets docs: wxControlWithItems

## Summary

### Types

wxControlWithItems()

### Functions

append(This, Item)

Appends item into the control.

append(This, Item, ClientData)

Appends item into the control.

appendStrings(This, Items)

Appends several items at once into the control.

appendStrings(This, Items, ClientsData)

Appends several items at once into the control.

clear(This)

Removes all items from the control.

delete(This, N)

Deletes an item from the control.

findString(This, String)

Equivalent to `findString(This, String, [])`.

findString/3

Finds an item whose label matches the given string.

getClientData(This, N)

Returns a pointer to the client data associated with the given item (if any).

getCount(This)

Returns the number of items in the control.

getSelection(This)

Returns the index of the selected item or `wxNOT\_FOUND` if no item is selected.

getString(This, N)

Returns the label of the item with the given index.

getStringSelection(This)

Returns the label of the selected item or an empty string if no item is selected.

insert(This, Item, Pos)

Inserts item into the control.

insert(This, Item, Pos, ClientData)

Inserts item into the control.

insertStrings(This, Items, Pos)

Inserts several items at once into the control.

insertStrings(This, Items, Pos, ClientsData)

Inserts several items at once into the control.

isEmpty(This)

Returns true if the control is empty or false if it has some items.

select(This, N)

This is the same as `setSelection/2` and exists only because it is slightly more natural for controls which support multiple selection.

setClientData(This, N, 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 `delete/2` or implicitly when the control itself is destroyed).

setSelection(This, N)

Sets the selection to the given item `n` or removes the selection entirely if `n` == `wxNOT\_FOUND`.

setString(This, N, String)

Sets the label for the given item.

setStringSelection(This, String)

Selects the item with the specified string in the control.

## Types

# wxControlWithItems()

    -type wxControlWithItems() :: wx:wx_object().

## Functions

# append(This, Item)

    -spec append(This, Item) -> integer() when This :: wxControlWithItems(), Item :: unicode:chardata().

Appends item into the control.

Return: The return value is the index of the newly inserted item. Note that this may be different from the last one if the control is sorted (e.g. has `wxLB_SORT` or `wxCB_SORT` style).

# append(This, Item, ClientData)

    -spec append(This, Item, ClientData) -> integer()
                    when This :: wxControlWithItems(), Item :: unicode:chardata(), ClientData :: term().

Appends item into the control.

Return: The return value is the index of the newly inserted item. Note that this may be different from the last one if the control is sorted (e.g. has `wxLB_SORT` or `wxCB_SORT` style).

# appendStrings(This, Items)

    -spec appendStrings(This, Items) -> integer()
                           when This :: wxControlWithItems(), Items :: [unicode:chardata()].

Appends several items at once into the control.

Notice that calling this method is usually much faster than appending them one by one if you need to add a lot of items.

# appendStrings(This, Items, ClientsData)

    -spec appendStrings(This, Items, ClientsData) -> integer()
                           when
                               This :: wxControlWithItems(),
                               Items :: [unicode:chardata()],
                               ClientsData :: [term()].

Appends several items at once into the control.

Notice that calling this method is usually much faster than appending them one by one if you need to add a lot of items.

# clear(This)

    -spec clear(This) -> ok when This :: wxControlWithItems().

Removes all items from the control.

`clear/1` also deletes the client data of the existing items if it is owned by the control.

# delete(This, N)

    -spec delete(This, N) -> ok when This :: wxControlWithItems(), N :: integer().

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.

If there is a currently selected item below the item being deleted, i.e. if `getSelection/1` returns a valid index greater than or equal to `n`, the selection is invalidated when this function is called. However if the selected item appears before the item being deleted, the selection is preserved unchanged.

See: `clear/1`

# findString(This, String)

    -spec findString(This, String) -> integer()
                        when This :: wxControlWithItems(), String :: unicode:chardata().

Equivalent to `findString(This, String, [])`.

# findString/3

    -spec findString(This, String, [Option]) -> integer()
                        when
                            This :: wxControlWithItems(),
                            String :: unicode:chardata(),
                            Option :: {bCase, boolean()}.

Finds an item whose label matches the given string.

Return: The zero-based position of the item, or wxNOT_FOUND if the string was not found.

# getClientData(This, N)

    -spec getClientData(This, N) -> term() when This :: wxControlWithItems(), N :: integer().

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

Notice that the returned pointer is still owned by the control and will be deleted by it, use `DetachClientObject()` (not implemented in wx) if you want to remove the pointer from the control.

Return: A pointer to the client data, or NULL if not present.

# getCount(This)

    -spec getCount(This) -> integer() when This :: wxControlWithItems().

Returns the number of items in the control.

See: `isEmpty/1`

# getSelection(This)

    -spec getSelection(This) -> integer() when This :: wxControlWithItems().

Returns the index of the selected item or `wxNOT\_FOUND` if no item is selected.

Return: The position of the current selection.

Remark: This method can be used with single selection list boxes only, you should use `wxListBox:getSelections/1` for the list boxes with wxLB_MULTIPLE style.

See:

- `setSelection/2`

- `getStringSelection/1`

# getString(This, N)

    -spec getString(This, N) -> unicode:charlist() when This :: wxControlWithItems(), N :: integer().

Returns the label of the item with the given index.

Return: The label of the item or an empty string if the position was invalid.

# getStringSelection(This)

    -spec getStringSelection(This) -> unicode:charlist() when This :: wxControlWithItems().

Returns the label of the selected item or an empty string if no item is selected.

See: `getSelection/1`

# insert(This, Item, Pos)

    -spec insert(This, Item, Pos) -> integer()
                    when This :: wxControlWithItems(), Item :: unicode:chardata(), Pos :: integer().

Inserts item into the control.

Return: The return value is the index of the newly inserted item. If the insertion failed for some reason, -1 is returned.

# insert(This, Item, Pos, ClientData)

    -spec insert(This, Item, Pos, ClientData) -> integer()
                    when
                        This :: wxControlWithItems(),
                        Item :: unicode:chardata(),
                        Pos :: integer(),
                        ClientData :: term().

Inserts item into the control.

Return: The return value is the index of the newly inserted item. If the insertion failed for some reason, -1 is returned.

# insertStrings(This, Items, Pos)

    -spec insertStrings(This, Items, Pos) -> integer()
                           when
                               This :: wxControlWithItems(), Items :: [unicode:chardata()], Pos :: integer().

Inserts several items at once into the control.

Notice that calling this method is usually much faster than inserting them one by one if you need to insert a lot of items.

Return: The return value is the index of the last inserted item. If the insertion failed for some reason, -1 is returned.

# insertStrings(This, Items, Pos, ClientsData)

    -spec insertStrings(This, Items, Pos, ClientsData) -> integer()
                           when
                               This :: wxControlWithItems(),
                               Items :: [unicode:chardata()],
                               Pos :: integer(),
                               ClientsData :: [term()].

Inserts several items at once into the control.

Notice that calling this method is usually much faster than inserting them one by one if you need to insert a lot of items.

Return: The return value is the index of the last inserted item. If the insertion failed for some reason, -1 is returned.

# isEmpty(This)

    -spec isEmpty(This) -> boolean() when This :: wxControlWithItems().

Returns true if the control is empty or false if it has some items.

See: `getCount/1`

# select(This, N)

    -spec select(This, N) -> ok when This :: wxControlWithItems(), N :: integer().

This is the same as `setSelection/2` and exists only because it is slightly more natural for controls which support multiple selection.

# setClientData(This, N, Data)

    -spec setClientData(This, N, Data) -> ok
                           when This :: wxControlWithItems(), N :: integer(), Data :: term().

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 `delete/2` 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.

# setSelection(This, N)

    -spec setSelection(This, N) -> ok when This :: wxControlWithItems(), N :: integer().

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.

See:

- `setString/3`

- `setStringSelection/2`

# setString(This, N, String)

    -spec setString(This, N, String) -> ok
                       when This :: wxControlWithItems(), N :: integer(), String :: unicode:chardata().

Sets the label for the given item.

# setStringSelection(This, String)

    -spec setStringSelection(This, String) -> boolean()
                                when This :: wxControlWithItems(), String :: unicode:chardata().

Selects the item with the specified string in the control.

This method doesn't cause any command events to be emitted.

Notice that this method is case-insensitive, i.e. the string is compared with all the elements of the control case-insensitively and the first matching entry is selected, even if it doesn't have exactly the same case as this string and there is an exact match afterwards.

Return: true if the specified string has been selected, false if it wasn't found in the control.