Back to Devexpress

CheckBoxFormControl Interface

officefileapi-devexpress-dot-spreadsheet-9f2df74a.md

latest6.1 KB
Original Source

CheckBoxFormControl Interface

A check box form control.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface CheckBoxFormControl :
    FormControl,
    Shape,
    FloatingObject,
    ShapeFormatBase,
    TextFormControl,
    LinkedCellFormControl,
    ShadedFormControl
vb
Public Interface CheckBoxFormControl
    Inherits FormControl,
             Shape,
             FloatingObject,
             ShapeFormatBase,
             TextFormControl,
             LinkedCellFormControl,
             ShadedFormControl

The following members return CheckBoxFormControl objects:

Remarks

Create a Check Box Form Control

The code sample below creates a checkbox control:

csharp
using DevExpress.Spreadsheet;

Workbook workbook = new Workbook();
workbook.LoadDocument("Document.xlsx");
var cellRange = workbook.Worksheets[0].Range["B2:C4"];
var checkBoxControl = formControls.AddCheckBox(cellRange);
checkBoxControl.CheckState = FormControlCheckState.Checked;
checkBoxControl.PlainText = "Reviewed";
vb
Imports DevExpress.Spreadsheet

Dim workbook As New Workbook()
workbook.LoadDocument("Document.xlsx")
Dim cellRange = workbook.Worksheets(0).Range("B2:C4")
Dim checkBoxControl = formControls.AddCheckBox(cellRange)
checkBoxControl.CheckState = FormControlCheckState.Checked
checkBoxControl.PlainText = "Reviewed"

Note

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

Obtain Check 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 Check Box Form Controls

Use the CheckBoxFormControl class properties to change checkbox parameters. The code sample below obtains all checkboxes, unchecks them, 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 checkBoxes = formControls.Where(formControl => formControl.FormControlType == FormControlType.CheckBox).Cast<CheckBoxFormControl>();
foreach (CheckBoxFormControl checkBox in checkBoxes) {
    checkBox.Shading3D = true;
    checkBox.CheckState = FormControlCheckState.Unchecked;
}
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)()
For Each checkBox As CheckBoxFormControl In checkBoxes
  checkBox.Shading3D = True
  checkBox.CheckState = FormControlCheckState.Unchecked
Next checkBox

Remove Check Box 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 check 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.CheckBox)
        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.CheckBox Then
    formControls.RemoveAt(i)
  End If
Next i

See Also

CheckBoxFormControl Members

DevExpress.Spreadsheet Namespace