//create a new workbook var workbook = new GrapeCity.Documents.Excel.Workbook(); IWorksheet ws = workbook.Worksheets["Sheet1"]; ws.Range["A:A"].ColumnWidthInPixel = 28d; // No data binding ws.Range["B2"].Value = "List boxes support unbound mode. You can add items with code."; var listBox1 = ws.Controls.AddListBox(23.6, 32.8, 170, 80.9); listBox1.Items.Add(new ListBoxItem("Unbound Item 1")); listBox1.Items.Add(new ListBoxItem("Unbound Item 2")); listBox1.Items.Add(new ListBoxItem("Unbound Item 3")); listBox1.SelectedIndex = 0; // Items source binding ws.Range["B10"].Value = "You can also use data binding to set the item source and bind selected index."; ws.Range["F11:F14"].Value = (new object[,] { { "Items"}, { "Item 1"}, { "Item 2"}, { "Item 3"} }); ws.Range["G11:G12"].Value = (new object[,] { { "Value"}, { 1d} }); var listBox2 = ws.Controls.AddListBox(23.7, 153.7, 170, 80.30); listBox2.ItemsSourceRange = ws.Range["F12:F14"]; listBox2.LinkedCell = ws.Range["G12"]; listBox2.SelectedIndex = 0; // Multi-select ws.Range["B18"].Value = "You can select multiple items if you change the selection mode."; var listBox3 = ws.Controls.AddListBox(24.1, 273.1, 170, 78.69); listBox3.Items.Add(new ListBoxItem("Multi-select Item 1")); listBox3.Items.Add(new ListBoxItem("Multi-select Item 2")); listBox3.Items.Add(new ListBoxItem("Multi-select Item 3")); listBox3.SelectionMode = SelectionMode.Extended; listBox3.SelectedItems.Add(listBox3.Items[0]); listBox3.SelectedItems.Add(listBox3.Items[2]); // Save to an excel file workbook.Save("ListBoxesBasicUsage.xlsx");
' Create a new Workbook Dim workbook As New Workbook Dim ws As IWorksheet = workbook.Worksheets("Sheet1") ws.Range("A:A").ColumnWidthInPixel = 28.0R ' No data binding ws.Range!B2.Value = "List boxes support unbound mode. You can add items with code." With ws.Controls.AddListBox(23.6, 32.8, 170, 80.9) With .Items .Add(New ListBoxItem("Unbound Item 1")) .Add(New ListBoxItem("Unbound Item 2")) .Add(New ListBoxItem("Unbound Item 3")) End With .SelectedIndex = 0 End With ' Items source binding ws.Range!B10.Value = "You can also use data binding to set the item source and bind selected index." ws.Range("F11:F14").Value = { {"Items"}, {"Item 1"}, {"Item 2"}, {"Item 3"} } ws.Range("G11:G12").Value = New Object(,) { {"Value"}, {1.0R} } With ws.Controls.AddListBox(23.7, 153.7, 170, 80.3) .ItemsSourceRange = ws.Range("F12:F14") .LinkedCell = ws.Range!G12 .SelectedIndex = 0 End With ' Multi-select ws.Range!B18.Value = "You can select multiple items if you change the selection mode." With ws.Controls.AddListBox(24.1, 273.1, 170, 78.69) With .Items .Add(New ListBoxItem("Multi-select Item 1")) .Add(New ListBoxItem("Multi-select Item 2")) .Add(New ListBoxItem("Multi-select Item 3")) End With .SelectionMode = SelectionMode.Extended .SelectedItems.Add(.Items(0)) .SelectedItems.Add(.Items(2)) End With ' save to an excel file workbook.Save("ListBoxesBasicUsage.xlsx")