Back to Devexpress

Worksheet.FormControls Property

officefileapi-devexpress-dot-spreadsheet-dot-worksheet-37edf32b.md

latest10.1 KB
Original Source

Worksheet.FormControls Property

Obtains a collection of form controls contained in a worksheet.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
FormControlCollection FormControls { get; }
vb
ReadOnly Property FormControls As FormControlCollection

Property Value

TypeDescription
FormControlCollection

A collection of form controls.

|

Remarks

Access 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.

The code snippet below shows how to get all check box form controls:

csharp
using DevExpress.Spreadsheet;
using System.Linq;

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

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

var checkBoxes = formControls.Where(formControl => formControl.FormControlType == FormControlType.CheckBox).Cast<CheckBoxFormControl>();
//...
vb
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.CheckBox).Cast(Of CheckBoxFormControl)()
'...

Create Form Controls

The table below lists available form controls and API used to create each type.

Form ControlClassMethod
ButtonButtonFormControlFormControlCollection.AddButton
Check BoxCheckBoxFormControlFormControlCollection.AddCheckBox
Combo boxComboBoxFormControlFormControlCollection.AddComboBox
Group boxGroupBoxFormControlFormControlCollection.AddGroupBox
List boxListBoxFormControlFormControlCollection.AddListBox
Radio ButtonRadioButtonFormControlFormControlCollection.AddRadioButton
ScrollbarScrollbarFormControlFormControlCollection.AddScrollbar
Spin ButtonSpinnerFormControlFormControlCollection.AddSpinner

Note

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

The code sample below creates a button form control:

csharp
using DevExpress.Spreadsheet;

Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");
var cellRange = workbook.Worksheets[0].Range["B2:C4"];
var buttonFormControl = formControls.AddButton(cellRange);
buttonFormControl.PlainText = "Click Here";
buttonFormControl.PrintObject = false;
vb
Imports DevExpress.Spreadsheet

Dim workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")
Dim cellRange = workbook.Worksheets(0).Range("B2:C4")
Dim buttonFormControl = formControls.AddButton(cellRange)
buttonFormControl.PlainText = "Click Here"
buttonFormControl.PrintObject = False

Available Export Formats

You can export workbooks with form controls to the following formats:

  • XLSX
  • XLSM
  • XLTX
  • XLTM
  • PDF

Disable Printing

Each form control has the PrintObject property that specifies whether to print the form control. This options also affects the following operations:

  • Form control export to PDF format
  • Export a cell range that contains a form control to an image
  • Export a worksheet with form controls to an image

Remove Form Controls

Call the FormControlCollection.Remove or FormControlCollection.RemoveAt method to remove a form control.

The FormControlCollection.Clear() method call removes all form controls from a worksheet.

Limitations

The Form Control API subset ships with the following limitations:

The following code snippets (auto-collected from DevExpress Examples) contain references to the FormControls property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheetcontrol-api-part-3/CS/SpreadsheetControl_API_Part03/CodeExamples/FormControlActions.cs#L15

csharp
#region #CreateFormControls
var formControls = workbook.Worksheets[0].FormControls;

wpf-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_WPF_API_Part02/SpreadsheetActions/FormControlActions.cs#L18

csharp
#region #CreateFormControls
var formControls = workbook.Worksheets[0].FormControls;

spreadsheet-document-api-examples-part2/CS/SpreadsheetDocServerAPIPart2/CodeExamples/FormControlActions.cs#L18

csharp
#region #CreateFormControls
var formControls = workbook.Worksheets[0].FormControls;

winforms-spreadsheetcontrol-api-part-3/VB/SpreadsheetControl_API_Part03/CodeExamples/FormControlActions.vb#L14

vb
#Region "#CreateFormControls"
            Dim formControls = workbook.Worksheets(CInt((0))).FormControls
            ' Create a button form control:

spreadsheet-document-api-examples-part2/VB/SpreadsheetDocServerAPIPart2/CodeExamples/FormControlActions.vb#L15

vb
' #Region "#CreateFormControls"
            Dim formControls = workbook.Worksheets(0).FormControls

See Also

Worksheet Interface

Worksheet Members

DevExpress.Spreadsheet Namespace