0

I'm trying to create a drop-down list on a grid. I was following the advice on this page. However, I'm not able to enter any string values for UserEnteredValue. The underlined error I'm getting:

Cannot implicitly convert type 'Google.Apis.Sheets.v4.Data.ConditionValue' to 'System.Collections.Generic.IList'.An explicit conversion exists(are you missing a cast?)

    public Request createDataValidationRequest(int sheetID, int startRow, int endRow, int startColumn, int endColumn)
    {
        var updateCellsRequest = new Request() {
            SetDataValidation = new SetDataValidationRequest()
            {
                Range = new GridRange()
                {
                    SheetId = sheetID,
                    StartRowIndex = startRow,
                    StartColumnIndex = startColumn,
                    EndRowIndex = endRow,
                    EndColumnIndex = endColumn
                },
                Rule = new DataValidationRule()
                {
                    Condition = new BooleanCondition()
                    {
                        Type = "ONE_OF_LIST",
                        Values = new ConditionValue()
                        {
                            UserEnteredValue = "awer"
                        }
                    },
                    InputMessage = "Select an Option",
                    ShowCustomUi = true,
                    Strict = true
                }
            }
        };
        return updateCellsRequest;
    }
TheMaster
  • 45,448
  • 6
  • 62
  • 85

1 Answers1

0

I was able to get the following, for my situation to work.

                        SpreadsheetsResource.GetRequest request = _sheetsService.Spreadsheets.Get(newTimeSheet.Id);
                        Spreadsheet spreadsheet = request.Execute();
                        SheetProperties timeSheetProperties = new SheetProperties();
                        for (int z = 0; z < spreadsheet.Sheets.Count; z++)
                        {
                            SheetProperties sheetProperties = spreadsheet.Sheets[z].Properties;
                            if (sheetProperties.Title == "3c TIME")
                            {
                                timeSheetProperties = sheetProperties;
                                break;
                            }
                        }
                        var updateCellsRequest = new Request()
                        {
                            SetDataValidation = new SetDataValidationRequest()
                            {
                                Range = new GridRange()
                                {
                                    SheetId = timeSheetProperties.SheetId,
                                    StartRowIndex = 2,
                                    StartColumnIndex = 0,
                                    EndColumnIndex = 1
                                },
                                Rule = new DataValidationRule()
                                {
                                    Condition = new BooleanCondition()
                                    {
                                        //Type = "ONE_OF_RANGE",
                                        Type = "ONE_OF_LIST",
                                        Values = new List<ConditionValue>()
                                    {
                                        new ConditionValue()
                                        {
                                            UserEnteredValue = "YES",
                                        },
                                        new ConditionValue()
                                        {
                                            UserEnteredValue = "NO",
                                        },
                                        new ConditionValue()
                                        {
                                            UserEnteredValue = "MAYBE",
                                        }
                                    }
                                    },
                                    InputMessage = "Select an Option",
                                    ShowCustomUi = true,
                                    Strict = true
                                }
                            }
                        };
                        var requestBody = new Google.Apis.Sheets.v4.Data.BatchUpdateSpreadsheetRequest();
                        var requests = new List<Request>();
                        requests.Add(updateCellsRequest);
                        requestBody.Requests = requests;
                        var batchRequest = _sheetsService.Spreadsheets.BatchUpdate(requestBody, newTimeSheet.Id);
                        batchRequest.Execute();
Doug Barense
  • 391
  • 3
  • 8