officefileapi-devexpress-dot-spreadsheet-6d279fe9.md
List box form control.
Namespace : DevExpress.Spreadsheet
Assembly : DevExpress.Spreadsheet.v25.2.Core.dll
NuGet Package : DevExpress.Spreadsheet.Core
public interface ListBoxFormControl :
FormControl,
Shape,
FloatingObject,
ShapeFormatBase,
DataSelectorFormControl,
LinkedCellFormControl,
ShadedFormControl
Public Interface ListBoxFormControl
Inherits FormControl,
Shape,
FloatingObject,
ShapeFormatBase,
DataSelectorFormControl,
LinkedCellFormControl,
ShadedFormControl
The following members return ListBoxFormControl objects:
The code sample below creates a list box control:
using DevExpress.Spreadsheet;
Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");
var cellRange = spreadsheetControl.Document.Worksheets[0].Range["B2:D2"];
var listBoxControl = formControls.AddListBox(cellRange);
listBoxControl.DropDownLines = 3;
listBoxControl.SourceRange = spreadsheetControl.Document.Worksheets[0].Range["E2:E6"];
listBoxControl.SelectedIndex = 1;
Imports DevExpress.Spreadsheet
Dim workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")
Dim cellRange = spreadsheetControl.Document.Worksheets(0).Range("B2:D2")
Dim listBoxControl = formControls.AddListBox(cellRange)
listBoxControl.DropDownLines = 3
listBoxControl.SourceRange = spreadsheetControl.Document.Worksheets(0).Range("E2:E6")
listBoxControl.SelectedIndex = 1
Note
The FormControlCollection.AddListBox method call adds a new item to both FormControlCollection and ShapeCollection.
The Worksheet.FormControls property obtains all form controls in a worksheet. You can use one of the following ways to obtain a specific form control:
The FormControl.Id and FormControl.Name properties return the form control’s identifier and name.
Use the ListBoxFormControl class properties to change list box parameters. The code sample below obtains all list boxes and enables 3D shading and multiple selection:
using DevExpress.Spreadsheet;
using System.Linq;
Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");
var formControls = workbook.Worksheets[0].FormControls;
var listBoxes = formControls.Where(formControl => formControl.FormControlType == FormControlType.ListBox).Cast<ListBoxFormControl>();
foreach (ListBoxFormControl listBox in listBoxes) {
listBox.Shading3D = true;
listBox.SelectionMode = FormControlSelectionMode.Extended;
}
Imports DevExpress.Spreadsheet
Imports System.Linq
Private workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")
Dim formControls = workbook.Worksheets(0).FormControls
Dim checkBoxes = formControls.Where(Function(formControl) formControl.FormControlType = FormControlType.ListBox).Cast(Of ListBoxFormControl)()
For Each listBox As ListBoxFormControl In listBoxes
listBox.Shading3D = True
listBox.SelectionMode = FormControlSelectionMode.Extended
Next listBox
Call the FormControlCollection.Remove or FormControlCollection.RemoveAt method to remove a form control. The FormControlCollection.Clear() method removes all form controls from a worksheet.
The code sample below removes all list boxes from a worksheet:
Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");
var formControls = workbook.Worksheets[0].FormControls;
for (int i = formControls.Count - 1; i >= 0; i--) {
if (formControls[i].FormControlType == FormControlType.ListBox)
formControls.RemoveAt(i);
}
Dim workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")
Dim formControls = workbook.Worksheets(0).FormControls
For i As Integer = formControls.Count - 1 To 0 Step -1
If formControls(i).FormControlType = FormControlType.ListBox Then
formControls.RemoveAt(i)
End If
Next i
The Form Control API subset ships with the following list box limitations:
null for ListBoxFormControl.See Also