Custom Cell In-place Editors

This topic describes how to assign custom in-place editors to worksheet cells. An in-place editor in the Spreadsheet is activated when a user double-clicks a cell or presses F2 when a cell is selected. Custom cell editors can help you implement multiple usage scenarios such as the ability to create a data entry form within a workbook.

Select a Custom Editor from a Predefined Set

The SpreadsheetControl supports a predefined set of editors you can assign to cells without any configuration. This set includes:

// Use a date editor as the in-place editor for cells located in the "Order Date" column.
Range dateEditRange = worksheet["Table[Order Date]"];
worksheet.CustomCellInplaceEditors.Add(dateEditRange, CustomCellInplaceEditorType.DateEdit);
// Use a combo box as the in-place editor for cells located in the "Category" column.// The editor's items are obtained from a cell range in the current worksheet.
Range 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.
Range checkBoxRange = worksheet["Table[Discount]"];
worksheet.CustomCellInplaceEditors.Add(checkBoxRange, CustomCellInplaceEditorType.CheckBox);

VB

' Use a date editor as the in-place editor for cells located in the "Order Date" column.Dim dateEditRange As Range = 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.' The editor's items are obtained from a cell range in the current worksheet.Dim comboBoxRange As Range = 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.Dim checkBoxRange As Range = worksheet("Table[Discount]")
worksheet.CustomCellInplaceEditors.Add(checkBoxRange, CustomCellInplaceEditorType.CheckBox)

Use the CustomCellEdit event to Assign Your Own Editor to a Cell

If custom editors from the predefined set do not comply with your requirements, handle the SpreadsheetControl.CustomCellEdit event to assign your own editor to a cell. This event fires each time an end-user starts to edit a cell and allows you to replace the built-in cell editor with a custom one. The event's Cell, RowIndex and ColumnIndex parameters help you identify the currently edited cell. To supply a custom editor to the cell, create a RepositoryItem descendant corresponding to the editor you want to use and assign it to the event's SpreadsheetCustomCellEditEventArgs.RepositoryItem parameter. Refer to the Repositories and Repository Items topic for additional information on this mechanism. The Editors document lists available editors and their corresponding repository items.

The code snippet below shows how to assign a spin editor to the sixth column's cells.