//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet ws = workbook.Worksheets["Sheet1"]; ws.Range["A:A"].ColumnWidthInPixel = 25d; // Add items (unbound mode) ws.Range["B2"].Value = "Drop downs support unbound mode. You can add items with code."; var dropBox1 = ws.Controls.AddDropDown(21.55, 38.4, 276.4, 30.19); dropBox1.Items.Add(new DropDownItem("Unbound Item 1")); dropBox1.Items.Add(new DropDownItem("Unbound Item 2")); dropBox1.Items.Add(new DropDownItem("Unbound Item 3")); dropBox1.SelectedIndex = 0; // Specify a items source range ws.Range["B7"].Value = "You can also use data binding to set the item source and bind selected index."; ws.Range["B12:B15"].Value = new object[,] { { "Items"}, { "Item 1"}, { "Item 2"}, { "Item 3"} }; ws.Range["D12:D13"].Value = new object[,] { { "Value"}, { 1d} }; var dropBox2 = ws.Controls.AddDropDown(20.95, 123.8, 279.90, 26.50); dropBox2.ItemsSourceRange = ws.Range["B13:B15"]; dropBox2.LinkedCell = ws.Range["D13"]; dropBox2.SelectedIndex = 0; // Save to an excel file workbook.Save("DropDownsBasicUsage.xlsx");
' Create a new Workbook Dim workbook As New Workbook Dim ws As IWorksheet = workbook.Worksheets("Sheet1") ws.Range("A:A").ColumnWidthInPixel = 25.0R ' Add items (unbound mode) ws.Range!B2.Value = "Drop downs support unbound mode. You can add items with code." With ws.Controls.AddDropDown(21.55, 38.4, 276.4, 30.19) With .Items .Add(New DropDownItem("Unbound Item 1")) .Add(New DropDownItem("Unbound Item 2")) .Add(New DropDownItem("Unbound Item 3")) End With .SelectedIndex = 0 End With ' Specify a items source range ws.Range!B7.Value = "You can also use data binding to set the item source and bind selected index." ws.Range("B12:B15").Value = { {"Items"}, {"Item 1"}, {"Item 2"}, {"Item 3"} } ws.Range("D12:D13").Value = New Object(,) { {"Value"}, {1.0R} } With ws.Controls.AddDropDown(20.95, 123.8, 279.9, 26.5) .ItemsSourceRange = ws.Range("B13:B15") .LinkedCell = ws.Range!D13 .SelectedIndex = 0 End With ' save to an excel file workbook.Save("DropDownsBasicUsage.xlsx")