Sam Scholefield
Sam Scholefield

Reputation: 1250

GAS - define listBox() displayed value

I have a form built and displayed in UiApp which uses the listBox class. My listBoxes are created as in the example below:

var yearText = app.createListBox().setName("yearText")
                  .addItem("")
                  .addItem("Reception")
                  .addItem("Nursery");

When the form loads for the first time they default to display blank (the value at index 0). What I am trying to do is reload the form with stored data, populating the listBox with it's saved value whilst still offering the same options as above (blank, Reception, Nursery).

I have tried using the various setValue methods available to the listBox class but I am not making any progress (variations of setValue are working fine for textArea, checkBox and dateBox classes elsewhere in the form). Any help or guidance gratefully received!

Upvotes: 0

Views: 106

Answers (1)

Serge insas
Serge insas

Reputation: 46802

The method for that is setItemSelected(index,Boolean), example below

function doGet(){
  var app = UiApp.createApplication();
  var list = app.createListBox().addItem('').addItem('v2').addItem('v3').addItem('v4').setItemSelected(2,true);
  app.add(list);
  return app;
}

Or also : setSelectedIndex(index) (same link for doc

example below too

function doGet(){
  var app = UiApp.createApplication();
  var list = app.createListBox().addItem('').addItem('v2').addItem('v3').addItem('v4').setSelectedIndex(2);
  app.add(list);
  return app;
}

Upvotes: 1

Related Questions