# Use controlP5 listBox to select string

**URL:** https://discourse.processing.org/t/use-controlp5-listbox-to-select-string/16923
**Category:** Libraries
**Created:** [January 7, 2020, 2:15am UTC](https://discourse.processing.org/t/use-controlp5-listbox-to-select-string/16923 "2020-01-07T02:15:59Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![rhole](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@rhole](https://discourse.processing.org/u/rhole)
#### Post date: [January 7, 2020, 2:15am UTC](https://discourse.processing.org/t/use-controlp5-listbox-to-select-string/16923/1 "2020-01-07T02:15:59Z")

</div>

I am looking at an example from the older forum. I am using version 3.5.3. I can get this sample to work, partially, by commenting out the two lines with “theEvent.group().value()” which give the error “The function value() does not exist.”  
Perhaps I am missing a library.

```auto
import controlP5.*;
ControlP5 controlP5;

// add an int variable which will store the
// id of the latest selected listbox item.
int myCurrentIndex = 0;
// make the list of tokens global, then it is
// accessible in both setup and draw 
String[] tokens;

void setup( ) {
  size(470, 295);

  controlP5 = new ControlP5(this);
  ListBox l = controlP5.addListBox("myList",20,40,80,200);

  // creating an arbitrary String array, add values
  // to the array and add new items to the listbox 
  // at the same time. value of each item added to the listbox 
  // corresponds to the token in the string array 'tokens'.
  tokens = new String[1000];
  for (int k = 0; k < tokens.length; k++){
    tokens[k] = k+"-item";
    l.addItem(tokens[k], k);
  }
}

void controlEvent(ControlEvent theEvent) {
  if (theEvent.isGroup()) {
    // an event from a group e.g. scrollList
      println(theEvent.group().value() +" from "+theEvent.group());
      // controlEvent is called when a listbox-item
      // has been activated, hence update the value
      // of myCurrentIndex accordingly
      myCurrentIndex = int(theEvent.group().value());
    }
}

void draw(){
  background(0);
  fill(255);
  // display and draw a token as text
  text(tokens[myCurrentIndex],200,40);
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [January 7, 2020, 2:42am UTC](https://discourse.processing.org/t/use-controlp5-listbox-to-select-string/16923/2 "2020-01-07T02:42:58Z")

</div>

sorry, but did you see in the example ListBox following info?

> // ListBox is DEPRECATED,  
> // use ScrollableList instead,

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [January 7, 2020, 2:50am UTC](https://discourse.processing.org/t/use-controlp5-listbox-to-select-string/16923/3 "2020-01-07T02:50:39Z")

</div>

I checked the examples and this is what I found about groups. I do not have the info or docs to describe the proper way to setup groups. However, the following did the trick:

```java
void controlEvent(ControlEvent theEvent) {  
    myCurrentIndex = int(theEvent.getValue());
    println("Watch: " + myCurrentIndex);
}

```

Kf

---

<div class="post-metadata">

### Author: ![rhole](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@rhole](https://discourse.processing.org/u/rhole)
#### Post date: [January 7, 2020, 4:03am UTC](https://discourse.processing.org/t/use-controlp5-listbox-to-select-string/16923/4 "2020-01-07T04:03:36Z")

</div>

Thanks. Both responses worked. group() is also depricated.
