Hide

Class ListBox

ListBox

Deprecated. The UI service was deprecated on December 11, 2014. To create user interfaces, use the HTML service instead.

A widget that presents a list of choices to the user, either as a list box or as a drop-down list.

Here is an example usage, which should be executed from within a spreadsheet bound script.

 

 // execute this in a spreadsheet
 function show() {
   var doc = SpreadsheetApp.getActiveSpreadsheet();
   var app = UiApp.createApplication().setTitle('My Application');
   var panel = app.createVerticalPanel();
   var lb = app.createListBox(true).setId('myId').setName('myLbName');

   // add items to ListBox
   lb.setVisibleItemCount(3);
   lb.addItem('first');
   lb.addItem('second');
   lb.addItem('third');
   lb.addItem('fourth');
   lb.addItem('fifth');
   lb.addItem('sixth');

   panel.add(lb);
   var button = app.createButton('press me');
   var handler = app.createServerClickHandler('click').addCallbackElement(panel);
   button.addClickHandler(handler);
   panel.add(button);
   app.add(panel);
   doc.show(app);
 }


 function click(eventInfo) {
   var app = UiApp.getActiveApplication();
   // get values of ListBox
   var value = eventInfo.parameter.myLbName;
   // multi select box returns a comma separated string
   var n = value.split(',');

   var doc = SpreadsheetApp.getActiveSpreadsheet();
   doc.getRange('a1').setValue(value);
   doc.getRange('b1').setValue('there are ' + n.length + ' items selected');
   return app;
 }
 

Internally, UiApp widgets are built on top of the Google Web Toolkit, and it can sometimes be helpful to look at the GWT documentation directly. You can find the ListBox documentation here.

Deprecated methods













































Send feedback about...

Apps Script