Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]General Information
[Collapse]WinForms Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Diagrams
  [Expand]Gauges
  [Expand]Map Control
  [Expand]Scheduler
  [Collapse]Spreadsheet
   [Expand]Product Information
    Product Structure
    Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Spreadsheet Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Table Overview
   [Expand]Charting Overview
    Printing
    Events
   [Expand]Mail Merge Overview
    Protection
    Find and Replace
   [Expand]Visual Elements
    Services
   [Expand]Shortcuts
   [Collapse]Examples
    [Expand]Files
    [Expand]Workbooks
    [Expand]Worksheets
    [Expand]Rows and Columns
    [Expand]Cells
    [Expand]Formulas
    [Expand]Import and Export Data
    [Expand]Data Binding
    [Expand]Mail Merge
    [Expand]Formatting Cells
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Expand]Tables
    [Expand]Pivot Tables
    [Expand]Printing
    [Expand]Pictures
    [Expand]Charts
    [Expand]Protection
    [Collapse]Customization
      How to: Customize or Hide the Popup Menu
      How to: Replace Built-In Command with a Custom Command
      How to: Assign Custom In-place Editors to Worksheet Cells
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]Printing-Exporting
  [Expand]PDF Viewer
   Reporting
  [Expand]Snap
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Reporting
[Expand]Report Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Assign Custom In-place Editors to Worksheet Cells

This example explains how to provide custom in-place editors for cells in a worksheet. A cell in-place editor in the Spreadsheet control is activated when an end-user double-clicks a cell or press F2 when a cell is selected. With custom cell editors, you can address multiple usage scenarios such as an ability to create a data entry form within a document to make the data input process as easy as possible for your end-users.

Expanded Predefined Cell In-Place Editors

A Spreadsheet control supports a set of predefined editors for in-place editing of cell values. These include: ComboBoxEdit, DateEdit and CheckEdit editors. Information about predefined cell in-place editors contained in a workbook is saved to a file in the XLS, XLSX, XLT, or XLTX formats, so these editors can be successfully restored when you load a document into the Spreadsheet control again.

Custom cell editors specified in a worksheet are stored in the CustomCellInplaceEditorCollection collection, which can be accessed by using the Worksheet.CustomCellInplaceEditors property. To assign a custom in-place editor of a particular type to a cell or cell range in a worksheet, use the CustomCellInplaceEditorCollection.Add method and pass the following parameters.

The CustomCellInplaceEditorCollection.Add method is overloaded to accept two optional parameters.

  • A value associated with a custom in-place editor. This value is represented by the ValueObject instance and can be used in the following way.

    If you use a combo box editor for cell editing (CustomCellInplaceEditorType.ComboBox), the ValueObject allows you to supply items for the editor's drop-down list. You can directly pass a string of comma-separated items to the CustomCellInplaceEditorCollection.Add method 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).

    The ValueObject instance is also associated with the SpreadsheetControl.CustomCellEdit event and provided through the event data class (SpreadsheetCustomCellEditEventArgs). Use the event's SpreadsheetCustomCellEditEventArgs.ValueObject parameter to obtain the ValueObject's value and then identify the custom editor to which this value belongs to adjust the editor's properties as required.

  • The useOnlyVisibleDataRange parameter. This Boolean parameter is relevant only for a combo box editor whose items originate from a cell range (using the ValueObject.FromRange property) and allows you to specify whether values of hidden cells should be included into the editor's item list. Using this parameter in other cases will trigger a System.ArgumentException.

The example below demonstrates how to use different custom cell editors to edit values of specific table columns.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T385401.

The image below shows the result.

Expanded User-Defined Cell In-Place Editors

If the predefined editors do not comply with your requirements, handle the SpreadsheetControl.CustomCellEdit event to assign your own custom editor to worksheet cells. This event fires when an end-user is about to start editing a cell and allows you to supply a custom in-place editor to the edited cell. The event's Cell parameter provides access to the cell for which the cell editor is activated. To provide an editor for editing a cell value, assign a corresponding RepositoryItem descendant to the event's SpreadsheetCustomCellEditEventArgs.RepositoryItem parameter. A repository item stores properties and events related to a specific editor. It has all the information required for creating a corresponding fully functional editor. Refer to the Editor Class Structure topic for additional information on this mechanism.

Important

The custom cell in-place editors assigned to cells using the SpreadsheetControl.CustomCellEdit event are not saved to a file.

In the code example above, cells of the "Quantity" table column have been marked as containing a custom cell in-place editor. The following example demonstrates how to use the SpreadsheetControl.CustomCellEdit event to assign a specific editor (SpinEdit) to these cells.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T385401.

The image below shows the result.

How would you rate this topic?​​​​​​​