MorningSleeper
MorningSleeper

Reputation: 415

Set data validation default

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());

Upvotes: 2

Views: 5310

Answers (1)

Wicket
Wicket

Reputation: 38218

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

Upvotes: 2

Related Questions