# Drop-Down List (lv_dropdown) (/widgets/dropdown)



Overview [#overview]

A Drop-Down List lets the user pick a value from a list.

It is closed by default and shows a single value or a fixed label. When
the user clicks it, the list opens; after a pick, the list closes again.

A Drop-Down is added to the default group (if one is set). It is an
editable widget — items can also be selected with an encoder or a
keyboard.

List items [#list-items]

<ApiLink name="lv_dropdown_set_options" display="lv_dropdown_set_options(dd, &#x22;First\nSecond\nThird&#x22;)" /> — items separated
by `\n`. The string is copied. Use `_set_options_static` to skip the copy
when the string lives in flash (cannot be combined with `_add_option`).
<ApiLink name="lv_dropdown_add_option" display="lv_dropdown_add_option(dd, &#x22;New&#x22;, pos)" /> inserts at index `pos`.
<ApiLink name="lv_dropdown_set_selected" display="lv_dropdown_set_selected(dd, id)" /> picks the active option by index.

Get selected option [#get-selected-option]

* <ApiLink name="lv_dropdown_get_selected" display="lv_dropdown_get_selected(dd)" /> returns the index.
* <ApiLink name="lv_dropdown_get_selected_str" display="lv_dropdown_get_selected_str(dd, buf, size)" /> copies the option text
  into `buf`.

Direction [#direction]

<ApiLink name="lv_dropdown_set_dir" display="lv_dropdown_set_dir(dd, LV_DIR_…)" /> chooses which side the list opens
toward (default <ApiLink name="LV_DIR_BOTTOM" />). Lists that would fall off the screen
are clamped to the edge automatically.

<LvglExample name="lv_example_dropdown_direction" path="widgets/dropdown/lv_example_dropdown_direction" />

Symbol [#symbol]

Add an indicator glyph (typically an arrow) with <ApiLink name="lv_dropdown_set_symbol" />.
It's rendered on the right by default; on the left when direction is
<ApiLink name="LV_DIR_LEFT" />.

```c title=" " lineNumbers=1
lv_dropdown_set_symbol(dropdown, LV_SYMBOL_DOWN);
```

Show selected [#show-selected]

By default the button shows the selected option. Set a fixed label with
<ApiLink name="lv_dropdown_set_text" display="lv_dropdown_set_text(dd, &#x22;Menu&#x22;)" /> (or `_set_text_static`) and the button
shows that string regardless of selection. Pass `NULL` to revert.

<LvglExample name="lv_example_dropdown_text" path="widgets/dropdown/lv_example_dropdown_text" />

Set translation tag [#set-translation-tag]

When using LVGL's [translation module](/main-modules/translation), you can bind a translation tag to a drop-down list directly.
After binding, future changes to the language will automatically update the bound text or options to
display the corresponding translation for that tag in the new language.

* <ApiLink name="lv_dropdown_set_text_translation_tag" display="lv_dropdown_set_text_translation_tag(dd, tag)" /> binds the
  button's fixed text (see [Show selected](#show-selected)).
* <ApiLink name="lv_dropdown_set_options_translation_tag" display="lv_dropdown_set_options_translation_tag(dd, tag)" /> binds the
  options. The translation should contain the options in a `\n` separated list, e.g. `"One\nTwo\nThree"`.

Calling any of the regular `lv_dropdown_set_text…`/`lv_dropdown_set_options…` functions (or
`lv_dropdown_add_option`/`lv_dropdown_clear_options`) afterwards removes the binding.

Programmatically open/close [#programmatically-openclose]

<ApiLink name="lv_dropdown_open" display="lv_dropdown_open(dd)" /> and <ApiLink name="lv_dropdown_close" display="lv_dropdown_close(dd)" />.

Styling [#styling]

The widget has two parts: the **button** (opens the list when clicked)
and the **list** (shown while open). Each part has its own selectors:

**Button**

* <ApiLink name="LV_PART_MAIN" /> — background + text of the closed button. Picks up
  <ApiLink name="LV_STATE_CHECKED" /> while the list is open.
* <ApiLink name="LV_PART_INDICATOR" /> — the symbol set with <ApiLink name="lv_dropdown_set_symbol" />.

**List** (accessed via <ApiLink name="lv_dropdown_get_list" display="lv_dropdown_get_list(dd)" />)

* <ApiLink name="LV_PART_MAIN" /> — list background. `max_height` caps the open list size.
* <ApiLink name="LV_PART_SCROLLBAR" /> — scrollbar.
* <ApiLink name="LV_PART_SELECTED" /> — the highlighted/pressed option:
  * <ApiLink name="LV_STATE_CHECKED" /> — used for the currently active option
  * <ApiLink name="LV_STATE_PRESSED" /> — used for the option is being pressed by touch or
    the Enter key is being pressed

To restyle the list, just get it, and add a style:

```c title=" " lineNumbers=1
lv_obj_t * list = lv_dropdown_get_list(dd);
lv_obj_add_style(list, &my_style, LV_PART_SELECTED);
```

<LvglExample name="lv_example_dropdown_styling" path="widgets/dropdown/lv_example_dropdown_styling" />

Data binding [#data-binding]

Data bindings connect a widget property to a piece of global data — a
[Subject](/main-modules/data_binding/subjects). When the subject's value
changes, every widget bound to it updates automatically; and an
interactive widget can write back into the subject so other subscribers
see the new value.

A Drop-Down binds its selected index to a Subject. The link is two-way:
picking an option updates the subject, and an application-side write into
the subject moves the selection. Only integer subjects are supported.

* <ApiLink name="lv_dropdown_bind_value" display="lv_dropdown_bind_value(dropdown, subject)" />

To show the value live in a label next to the widget, attach a label and call <ApiLink name="lv_label_bind_text" display="lv_label_bind_text(label, subject, &#x22;%d&#x22;)" /> — the format string accepts any printf-style specifier (XML: `bind_text` + `bind_text-fmt`).

<LvglExample name="lv_example_dropdown_bind_value" path="widgets/dropdown/lv_example_dropdown_bind_value" />

Events [#events]

* <ApiLink name="LV_EVENT_VALUE_CHANGED" /> Sent when a new option is selected or the list is opened/closed.
* <ApiLink name="LV_EVENT_CANCEL" /> Sent when list is closed.
* <ApiLink name="LV_EVENT_READY" /> Sent when list is opened.

<LvglExample name="lv_example_dropdown_event" path="widgets/dropdown/lv_example_dropdown_event" />

Learn more about [Events](/common-widget-features/events) emitted by all Widgets.

Keys [#keys]

* `LV_KEY_RIGHT/DOWN` Select next list item.
* `LV_KEY_LEFT/UP` Select previous list item.
* <ApiLink name="LV_KEY_ENTER" /> Apply selected list item (sends
  <ApiLink name="LV_EVENT_VALUE_CHANGED" /> event and closes Drop-Down List).

Learn more about [Keys](/main-modules/indev/keypad).
