Back to Devexpress

CustomCellInplaceEditorCollection.Add(CellRange, CustomCellInplaceEditorType, ValueObject) Method

officefileapi-devexpress-dot-spreadsheet-dot-customcellinplaceeditorcollection-dot-add-x28-devexpress-dot-spreadsheet-dot-cellrange-devexpress-dot-spreadsheet-dot-customcellinplaceeditortype-devexpress-dot-spreadsheet-dot-valueobject-x29.md

latest12.5 KB
Original Source

CustomCellInplaceEditorCollection.Add(CellRange, CustomCellInplaceEditorType, ValueObject) Method

Creates a custom cell in-place editor with the specified settings and assigns it to the specified cell range.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
CustomCellInplaceEditor Add(
    CellRange range,
    CustomCellInplaceEditorType editorType,
    ValueObject value
)
vb
Function Add(
    range As CellRange,
    editorType As CustomCellInplaceEditorType,
    value As ValueObject
) As CustomCellInplaceEditor

Parameters

NameTypeDescription
rangeCellRange

A CellRange object that specifies a cell or cell range to which the custom in-place editor should be assigned.

| | editorType | CustomCellInplaceEditorType |

A CustomCellInplaceEditorType enumeration member that specifies the type of the custom editor to be used for in-place editing.

| | value | ValueObject |

A ValueObject object that specifies a value associated with the custom cell in-place editor. For a combo box editor (CustomCellInplaceEditorType.ComboBox), this value specifies a list of items to be displayed in the editor’s drop-down list.

|

Returns

TypeDescription
CustomCellInplaceEditor

A CustomCellInplaceEditor object that specifies the created custom cell in-place editor.

|

Remarks

Use the Add method to assign an in-place editor of the predefined type to worksheet cells. If you use a combo box editor for cell editing (the editorType parameter is CustomCellInplaceEditorType.ComboBox), the method’s value parameter allows you to supply items for the editor’s drop-down list. You can directly pass a string of comma-separated items or use the ValueObject.FromRange method to obtain the required items from a cell range in a worksheet. Using types of values other than a text string or cell range is not allowed (otherwise, a System.ArgumentException will be raised).

If you select the CustomCellInplaceEditorType.Custom editor type, you must handle the SpreadsheetControl.CustomCellEdit event to define a specific editor to be assigned to the specified cell range.

For an example on how to use custom editors for in-place editing of cell content, refer to the How to: Assign Custom In-place Editors to Worksheet Cells article.

Example

View Example

csharp
// Use a date editor as the in-place editor for cells located in the "Order Date" column of the worksheet table.
CellRange dateEditRange = worksheet["Table[Order Date]"];
worksheet.CustomCellInplaceEditors.Add(dateEditRange, CustomCellInplaceEditorType.DateEdit);

// Use a combo box editor as the in-place editor for cells located in the "Category" column of the worksheet table.
// The editor's items are obtained from a cell range in the current worksheet.
CellRange comboBoxRange = worksheet["Table[Category]"];
worksheet.CustomCellInplaceEditors.Add(comboBoxRange, CustomCellInplaceEditorType.ComboBox, ValueObject.FromRange(worksheet["J3:J9"]));

// Use a check editor as the in-place editor for cells located in the "Discount" column of the worksheet table.
CellRange checkBoxRange = worksheet["Table[Discount]"];
worksheet.CustomCellInplaceEditors.Add(checkBoxRange, CustomCellInplaceEditorType.CheckBox);

// Use the custom control (SpinEdit) as the in-place editor for cells located in the "Quantity" column of the worksheet table.
// To provide the required editor, handle the CustomCellEdit event. 
CellRange customRange = worksheet["Table[Qty]"];
worksheet.CustomCellInplaceEditors.Add(customRange, CustomCellInplaceEditorType.Custom, "MySpinEdit");
vb
' Use a date editor as the in-place editor for cells located in the "Order Date" column of the worksheet table.
Dim dateEditRange As CellRange = worksheet("Table[Order Date]")
worksheet.CustomCellInplaceEditors.Add(dateEditRange, CustomCellInplaceEditorType.DateEdit)

' Use a combo box editor as the in-place editor for cells located in the "Category" column of the worksheet table.
' The editor's items are obtained from a cell range in the current worksheet.
Dim comboBoxRange As CellRange = worksheet("Table[Category]")
worksheet.CustomCellInplaceEditors.Add(comboBoxRange, CustomCellInplaceEditorType.ComboBox, ValueObject.FromRange(worksheet("J3:J9")))

' Use a check editor as the in-place editor for cells located in the "Discount" column of the worksheet table.
Dim checkBoxRange As CellRange = worksheet("Table[Discount]")
worksheet.CustomCellInplaceEditors.Add(checkBoxRange, CustomCellInplaceEditorType.CheckBox)

' Use the custom control (SpinEdit) as the in-place editor for cells located in the "Quantity" column of the worksheet table.
' To provide the required editor, handle the CustomCellEdit event. 
Dim customRange As CellRange = worksheet("Table[Qty]")
worksheet.CustomCellInplaceEditors.Add(customRange, CustomCellInplaceEditorType.Custom, "MySpinEdit")

The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(CellRange, CustomCellInplaceEditorType, ValueObject) method.

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-spreadsheet-control-create-a-data-entry-form/CS/DataEntryFormSample/MainForm.cs#L37

csharp
// Assign custom editors to worksheet cells.
sheet.CustomCellInplaceEditors.Add(sheet["D8"], CustomCellInplaceEditorType.Custom, "RegularHoursWorked");
sheet.CustomCellInplaceEditors.Add(sheet["D10"], CustomCellInplaceEditorType.Custom, "VacationHours");

wpf-spreadsheet-control-create-a-data-entry-form/CS/WpfDataEntryFormSample/MainWindow.xaml.cs#L34

csharp
//Assign custom editors to worksheet cells.
sheet.CustomCellInplaceEditors.Add(sheet["D8"], CustomCellInplaceEditorType.Custom, "RegularHoursWorked");
sheet.CustomCellInplaceEditors.Add(sheet["D10"], CustomCellInplaceEditorType.Custom, "VacationHours");

wpf-spreadsheet-assign-custom-in-place-editors/CS/WpfSpreadsheet_CustomCellEditors/MainWindow.xaml.cs#L39

csharp
CellRange comboBoxRange = worksheet["Table[Category]"];
worksheet.CustomCellInplaceEditors.Add(comboBoxRange, CustomCellInplaceEditorType.ComboBox, ValueObject.FromRange(worksheet["J3:J9"]));

winforms-spreadsheet-assign-custom-in-place-editors/CS/Spreadsheet_CustomCellEditors/Form1.cs#L39

csharp
CellRange comboBoxRange = worksheet["Table[Category]"];
worksheet.CustomCellInplaceEditors.Add(comboBoxRange, CustomCellInplaceEditorType.ComboBox, ValueObject.FromRange(worksheet["J3:J9"]));

winforms-spreadsheet-use-custom-cell-editors/VB/DevAVInvoicing/Form1.vb#L39

vb
Dim customers As Worksheet = workbook.Worksheets("Customers")
invoice.CustomCellInplaceEditors.Add(invoice("B10:C10"), CustomCellInplaceEditorType.ComboBox, ValueObject.FromRange(customers("A2:A21")))
' Use a combo box editor as the in-place editor for cells containing the store location in the Shipping Address section.

winforms-spreadsheet-control-create-a-data-entry-form/VB/DataEntryFormSample/MainForm.vb#L33

vb
'Assign custom editors to worksheet cells.
sheet.CustomCellInplaceEditors.Add(sheet("D8"), CustomCellInplaceEditorType.Custom, "RegularHoursWorked")
sheet.CustomCellInplaceEditors.Add(sheet("D10"), CustomCellInplaceEditorType.Custom, "VacationHours")

wpf-spreadsheet-control-create-a-data-entry-form/VB/WpfDataEntryFormSample/MainWindow.xaml.vb#L32

vb
'Assign custom editors to worksheet cells.
sheet.CustomCellInplaceEditors.Add(sheet("D8"), CustomCellInplaceEditorType.Custom, "RegularHoursWorked")
sheet.CustomCellInplaceEditors.Add(sheet("D10"), CustomCellInplaceEditorType.Custom, "VacationHours")

wpf-spreadsheet-assign-custom-in-place-editors/VB/WpfSpreadsheet_CustomCellEditors/MainWindow.xaml.vb#L34

vb
Dim comboBoxRange As CellRange = worksheet("Table[Category]")
worksheet.CustomCellInplaceEditors.Add(comboBoxRange, CustomCellInplaceEditorType.ComboBox, ValueObject.FromRange(worksheet("J3:J9")))
' Use a check editor as the in-place editor for cells located in the "Discount" column of the worksheet table.

winforms-spreadsheet-assign-custom-in-place-editors/VB/Spreadsheet_CustomCellEditors/Form1.vb#L34

vb
Dim comboBoxRange As CellRange = worksheet("Table[Category]")
worksheet.CustomCellInplaceEditors.Add(comboBoxRange, CustomCellInplaceEditorType.ComboBox, ValueObject.FromRange(worksheet("J3:J9")))
' Use a check editor as the in-place editor for cells located in the "Discount" column of the worksheet table.

See Also

Custom Cell In-place Editors

CustomCellInplaceEditorCollection Interface

CustomCellInplaceEditorCollection Members

DevExpress.Spreadsheet Namespace