wxRuby Documentation Home

# Wx::Choice

A choice item (also often called a ‘dropdown’) is used to select one of
a list of strings. Unlike a listbox, only the selection is visible until
the user pulls down the menu of choices. By using the client_data
functions inherited from ControlWithItems , ruby
objects can be associated with items within the dropdown.

## Derived from

ControlWithItems

Control

Window

EvtHandler

Object

## Window styles

There are no special styles for Choice.

See also window styles overview.

## Event handling

evt_choice(id) { | event | … } | Process a EVT_COMMAND_CHOICE_SELECTED event,when an item on the list is selected.

## See also

ListBox, ComboBox,
CommandEvent

## Methods

- Choice.new
- Choice#create
- Choice#delete
- Choice#get_columns
- Choice#get_current_selection
- Choice#set_columns

### Choice.new

Choice.new(%(arg-type)Window% parent, Integer id, Point pos, Size size, Array choices[], Integer style = 0, Validator validator = DEFAULT_VALIDATOR, String name = “choice”)

Constructor, creating and showing a choice.

#### Parameters

- parent Parent window. Must not be NULL.
- id Window identifier. A value of -1 indicates a default value.
- pos Window position.
- size Window size. If the default size (-1, -1) is specified then the choice is sized
  appropriately.
- choices An array of strings with which to initialise the choice control.
- style Window style. See Choice.
- validator Window validator.
- name Window name.

#### See also

Choice#create, Validator

### Choice#create

Boolean create(%(arg-type)Window% parent, Integer id, Point pos, Size size, Array choices[], Integer style = 0, Validator validator = DEFAULT_VALIDATOR, String name = “choice”)

Creates the choice for two-step construction. See Choice.new.

### Choice#delete

delete(%(arg-type)Integer% n)

Deletes the item with the given index from the control.

#### Parameters

- n The item to delete.

### Choice#get_columns

Integer get_columns()

Gets the number of columns in this choice item.

#### Remarks

This is implemented for Motif only and always returns `1` for the other
platforms.

### Choice#get_current_selection

Integer get_current_selection()

Unlike get_selection which only
returns the accepted selection value, i.e. the selection in the control once
the user closes the dropdown list, this function returns the current selection.
That is, while the dropdown list is shown, it returns the currently selected
item in it. When it is not shown, its result is the same as for the other
function.

### Choice#set_columns

set_columns(%(arg-type)Integer% n = 1)

Sets the number of columns in this choice item.

#### Parameters

- n Number of columns.

#### Remarks

This is implemented for Motif only and doesn’t do anything under other
platforms.

[This page automatically generated from the Textile source at 2023-06-09 00:45:35 +0000]