Skip to main content
Row

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

ICellValueConverter Interface

A converter that converts custom objects to cell values and vice versa.

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

#Declaration

public interface ICellValueConverter

The following members return ICellValueConverter objects:

#Example

To convert custom objects to cell values and vise versa, you can apply your own converters.

This example demonstrates how to convert a color object (Color) to a SpreadsheetControl-compatible cell value of the text type (CellValue) that corresponds to the color name. To do this, create a custom converter class that implements the ICellValueConverter interface, and call the CellValue.FromObject method with the color object and custom converter passed as parameters.

View Example

        Worksheet worksheet = workbook.Worksheets[0];
        Cell cell = worksheet.Cells["A1"];
        cell.FillColor = Color.Orange;
        cell.Value = CellValue.FromObject(cell.FillColor, new ColorToNameConverter());
        // ...
class ColorToNameConverter : ICellValueConverter {
    object ICellValueConverter.ConvertToObject(CellValue value) {
        return null;
    }
    CellValue ICellValueConverter.TryConvertFromObject(object value) {
        bool isColor = value.GetType() == typeof(Color);
        if (!isColor)
            return null;
        return ((Color)value).Name;
    }
}
See Also