wxRuby Documentation Home

# Wx::DatePickerCtrl

This control allows the user to select a date. Unlike
CalendarCtrl, which is a relatively big control,
DatePickerCtrl is implemented as a small window showing the currently selected date.
The control can be edited using the keyboard, and can also display a popup
window for more user-friendly date selection, depending on the styles used and
the platform, except PalmOS where date is selected using native dialog.

It is only available if `USE_DATEPICKCTRL` is set to $1$.

## Derived from

Control

Window

EvtHandler

Object

## Window styles

`DP_SPIN` | Creates a control without a month calendar drop down but with spin-control-like arrows to change individual date components. This style is not supported by the generic version.
`DP_DROPDOWN` | Creates a control with a month calendar drop-down part from which the user can select a date.
`DP_DEFAULT` | Creates a control with the style that is best supported for the current platform (currently DP_SPIN under Windows and DP_DROPDOWN elsewhere).
`DP_ALLOWNONE` | With this style, the control allows the user to not enter any valid date at all. Without it – the default – the control always has some valid date.
`DP_SHOWCENTURY` | Forces display of the century in the default date format. Without this style the century could be displayed, or not, depending on the default date representation in the system.

## Event handling

evt_date_changed(id) { | event | … } | This event fires when the userchanges the current selection in the control.

## See also

CalendarCtrl,

DateEvent

## Methods

- DatePickerCtrl.new
- DatePickerCtrl#create
- DatePickerCtrl#get_range
- DatePickerCtrl#get_value
- DatePickerCtrl#set_range
- DatePickerCtrl#set_value

### DatePickerCtrl.new

DatePickerCtrl.new(%(arg-type)Window% parent, Integer id, DateTime dt = DefaultDateTime, Point pos = DEFAULT_POSITION, Size size = DEFAULT_SIZE, Integer style = DP_DEFAULT | DP_SHOWCENTURY, Validator validator = DEFAULT_VALIDATOR, String name = “datectrl”)

Initializes the object and calls Create with
all the parameters.

### DatePickerCtrl#create

Boolean create(%(arg-type)Window% parent, Integer id, DateTime dt = DefaultDateTime, Point pos = DEFAULT_POSITION, Size size = DEFAULT_SIZE, Integer style = DP_DEFAULT | DP_SHOWCENTURY, Validator validator = DEFAULT_VALIDATOR, String name = “datectrl”)

#### Parameters

- parent Parent window, must not be non-`NULL`.
- id The identifier for the control.
- dt The initial value of the control, may be `nil` if flag `DP_ALLOWNONE` is set.
- pos Initial position.
- size Initial size. If left at default value, the control chooses its
  own best size by using the height approximately equal to a text control and
  width large enough to show the date string fully.
- style The window style, should be left at $0$ as there are no
  special styles for this control in this version.
- validator Validator which can be used for additional date checks.
- name Control name.

#### Return value

if the control was successfully created or if creation failed.

### DatePickerCtrl#get_range

Array get_range()

If the control had been previously limited to a range of dates using
set_range, returns the lower and upper
bounds of this range in an array. If no range is set (or only one of the bounds is set),
you’ll receive nil values in the array.

#### Return value

A two cells array containing the range. If no range set the array is `[nil, nil]`.

### DatePickerCtrl#get_value

DateTime get_value()

Returns the currently selected. If there is no selection or the selection is
outside of the current range, `nil` is returned.

### DatePickerCtrl#set_range

set_range(%(arg-type)DateTime% dt1, DateTime dt2)

Sets the valid range for the date selection. If dt1 is non `nil`, it becomes
the earliest date (inclusive) accepted by the control. If dt2 is non `nil`,
it becomes the latest possible date.

#### Remarks

If the current value of the control is outside of the newly set range bounds,
the behaviour is undefined.

### DatePickerCtrl#set_value

set_value(%(arg-type)DateTime% dt)

Changes the current value of the control. The date should be included
in the currently selected range, if any.
Pass `nil` to remove the selection, only applicable when the `DT_ALLOWNONE` flag is set.

Calling this method does not result in a date change event.

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