2

When I set a cells data validation from script I would like to set which of the choices is displayed by default, currently the data validation is written to the sheet with no item selected using code below. Is there any way to set it to "Vote"?

var option = new Array();
option[0]="Vote";
option[1]="Vote Up";
option[2]="Vote Down";

var dv = SpreadsheetApp.newDataValidation();
dv.setAllowInvalid(false);  
dv.setHelpText("Vote this item up or down.");
dv.requireValueInList(option, true);

localSheet.getRange(1,6).setDataValidation(dv.build());
MorningSleeper
  • 415
  • 1
  • 5
  • 13

1 Answers1

2

Use setValue(value). I.E. add the following line to your code:

localSheet.getRange(1,6).setValue("Vote");


Further reading regarding data validation and default values:
Setting defauld values in Data Validation drop-down list
Community
  • 1
  • 1
Rubén
  • 34,714
  • 9
  • 70
  • 166