Back to Devexpress

ComboBoxFormControl Interface

officefileapi-devexpress-dot-spreadsheet-1aa50a72.md

latest6.7 KB
Original Source

ComboBoxFormControl Interface

A combo box form control.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface ComboBoxFormControl :
    FormControl,
    Shape,
    FloatingObject,
    ShapeFormatBase,
    DataSelectorFormControl,
    LinkedCellFormControl,
    ShadedFormControl
vb
Public Interface ComboBoxFormControl
    Inherits FormControl,
             Shape,
             FloatingObject,
             ShapeFormatBase,
             DataSelectorFormControl,
             LinkedCellFormControl,
             ShadedFormControl

The following members return ComboBoxFormControl objects:

Remarks

Create a Combo Box Form Control

The code sample below creates a combo box control:

csharp
using DevExpress.Spreadsheet;

Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");
var cellRange = spreadsheetControl.Document.Worksheets[0].Range["B2:D2"];
var comboBoxControl = formControls.AddComboBox(cellRange);
comboBoxControl.DropDownLines = 3;
comboBoxControl.SourceRange = spreadsheetControl.Document.Worksheets[0].Range["E2:E6"];
comboBoxControl.SelectedIndex = 1;
vb
Imports DevExpress.Spreadsheet

Dim workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")
Dim cellRange = spreadsheetControl.Document.Worksheets(0).Range("B2:D2")
Dim comboBoxControl = formControls.AddComboBox(cellRange)
comboBoxControl.DropDownLines = 3
comboBoxControl.SourceRange = spreadsheetControl.Document.Worksheets(0).Range("E2:E6")
comboBoxControl.SelectedIndex = 1

Note

The FormControlCollection.AddComboBox method call adds a new item to both FormControlCollection and ShapeCollection.

Obtain Combo Box Form Controls

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.

Modify Combo Box Form Controls

Use the ComboBoxFormControl class properties to change combo box parameters. The code sample below obtains all combo boxes and enables 3D shading:

csharp
using DevExpress.Spreadsheet;
using System.Linq;

Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");

var formControls = workbook.Worksheets[0].FormControls;

var comboBoxes = formControls.Where(formControl => formControl.FormControlType == FormControlType.ComboBox).Cast<ComboBoxFormControl>();
foreach (ComboBoxFormControl comboBox in comboBoxes)
{
    comboBox.Shading3D = true;

}
vb
Imports DevExpress.Spreadsheet
Imports System.Linq

Private workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")

Dim formControls = workbook.Worksheets(0).FormControls

Dim comboBoxes = formControls.Where(Function(formControl) formControl.FormControlType = FormControlType.ComboBox).Cast(Of ComboBoxFormControl)()
For Each comboBox As ComboBoxFormControl In comboBoxes
  comboBox.Shading3D = True

Next comboBox

Remove Combo Box Form Controls

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 combo boxes from a worksheet:

csharp
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.ComboBox)
        formControls.RemoveAt(i);
}
vb
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.ComboBox Then
    formControls.RemoveAt(i)
  End If
Next i

Limitations

The Form Control API subset ships with the following combo box limitations:

  • You cannot change combo box value in the Spreadsheet Control for WinForms and WPF
  • Spreadsheet Control for WinForms and WPF does not display combo box values from a source range
  • ShapeFormatBase.Fill, ShapeFormatBase.Outline, and ShapeText property returns null for ComboBoxFormControl.

See Also

ComboBoxFormControl Members

DevExpress.Spreadsheet Namespace