We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Populate Default selected value to ComboBox in excel

Hi Team,
I am displaying combo box on excel. But I want to display combo box with selected default value when it load. e.g When combo box load first time on excel that time I want to display default selected value from list i.e. “Aspose.Grid”

Platform : .Net (C#)

------------------------------Dummy Code---------------------------------------
string[] items = new string[3];
items[0] = “Aspose”;
items[1] = “Aspose.Grid”;
items[2] = “Aspose.Grid.Desktop”;

        CellArea a = new CellArea();
        a.StartRow = 2;
        a.EndRow = 14;
        a.StartColumn = 4;
        a.EndColumn = 4;

        var flatList = string.Join(",", items.ToArray());
        ValidationCollection data  = this.worksheet.Validations;
        Validation v = data[data.Add(a)];
        v.Type = Aspose.Cells.ValidationType.List;
        v.Operator = OperatorType.Between;
        v.InCellDropDown = true;
        v.Formula1 = flatList;

Original Img.png (1.4 KB)
Wanted Output.png (1.7 KB)

@sachinmali26,

After adding the data validation to the range of cells. You may simply input your desired value to those cells (as your default selected value).
e.g.
Sample code:

Worksheet sheet = workbook.Worksheets[0];
.......
Cell cellE3  = sheet.Cells["E3"];
cellE3.PutValue("Aspose.Grid");
//or
//cellE3.PutValue(items[1]);
.....

Please note, for data validations in Excel, dropdown list would be activated when you select the cell (via keys or mouse) or start inserting some value to it, so you have to use Cell.PutValue() method to insert your default value to those cells.
Hope, this helps a bit.

1 Like

Resolved Thanks :slight_smile:

@sachinmali26,
You are welcome.