# controlP5 – Get selected dropdown item text as string?

**URL:** <https://discourse.processing.org/t/controlp5-get-selected-dropdown-item-text-as-string/11236>\
**Category:** Libraries\
**Created:** [May 14, 2019, 6:21pm UTC](https://discourse.processing.org/t/controlp5-get-selected-dropdown-item-text-as-string/11236 "2019-05-14T18:21:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ER-PIP](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@ER-PIP](https://discourse.processing.org/u/ER-PIP)\
**Post date:** [May 14, 2019, 6:21pm UTC](https://discourse.processing.org/t/controlp5-get-selected-dropdown-item-text-as-string/11236/1 "2019-05-14T18:21:53Z")

</div>

UPDATE-  
Needed to read some Java docs on how to use Map– here is my solution:

`cwDropdown.getItem((int)val).get("text")`

Though it returns as an Object rather than a String…

* * *

Hi-

I’m having a heck of a time getting the string of the selected item in a DropdownList or ScrollableList within controlP5.

On my selection event, I can’t seem to figure out what will pull the selected item’s TEXT or LABEL as a string.

```auto
/// Change colorway
   
val = theEvent.getController().getValue();

if (theEvent.getController().getName()== guiColorwayString) {

  // Displays something incorrect- possibly the initial value of the DropdownList?
  println(".getText() : " + theEvent.getController().getValueLabel().getText()); 
  
  // Displays "...valuelabel (255,255,255), name=WHITE on WHITE, text=WHITE on WHITE..." in Console but can't figure out how to "get" `name` or `text` as a string?
  println("cwDropdown: " + cwDropdown.getItem((int)val)); 

}

```

Any help would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [May 14, 2019, 9:27pm UTC](https://discourse.processing.org/t/controlp5-get-selected-dropdown-item-text-as-string/11236/2 "2019-05-14T21:27:04Z")

</div>

Did you see the example

[http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5dropdownList/ControlP5dropdownList.pde](http://www.sojamo.de/libraries/controlP5/examples/controllers/ControlP5dropdownList/ControlP5dropdownList.pde)

[http://www.sojamo.de/libraries/controlP5](http://www.sojamo.de/libraries/controlP5)

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [March 12, 2020, 5:49pm UTC](https://discourse.processing.org/t/controlp5-get-selected-dropdown-item-text-as-string/11236/3 "2020-03-12T17:49:59Z")

</div>

Just testing this code and it doesn’t seem to work anymore.

I get a bunch of errors not just the one.

The function setIndex(int) does not exist.
