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

IDataSourceColumnTypeDetector Interface

Provides the capability to identify the name and type of each column in a data source created from a cell range.

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

#Declaration

public interface IDataSourceColumnTypeDetector

The following members return IDataSourceColumnTypeDetector objects:

#Remarks

To specify column names and types using your own custom specifics, implement a class with the IDataSourceColumnTypeDetector interface and assign an instance of this class to the RangeDataSourceOptions.DataSourceColumnTypeDetector property of the options object passed to the CellRange.GetDataSource or the WorksheetDataBindingCollection.CreateDataSource method.

#Example

View Example

class MyColumnDetector : IDataSourceColumnTypeDetector {
    public string GetColumnName(int index, int offset, CellRange range) {
        if (offset > 3) return String.Format("Column{0}", index);
        string[] names = { "City", "Year", "Month", "Temperature" };
        return names[index];
    }

    public Type GetColumnType(int index, int offset, CellRange range) {
        Type defaultType = typeof(string);
        CellValue value = range[0, offset].Value;
        if (value.IsText) return typeof(string);
        if (value.IsBoolean) return typeof(bool);
        if (value.IsDateTime) return typeof(DateTime);
        if (value.IsNumeric) return typeof(double);
        return defaultType;
    }
}
See Also