Back to Devexpress

IDataSourceColumnTypeDetector Interface

officefileapi-devexpress-dot-spreadsheet-25fe232b.md

latest4.0 KB
Original Source

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.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
public interface IDataSourceColumnTypeDetector
vb
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

csharp
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;
    }
}
vb
Friend Class MyColumnDetector
    Implements IDataSourceColumnTypeDetector

    Public Function GetColumnName(ByVal index As Integer, ByVal offset As Integer, ByVal range As CellRange) As String Implements IDataSourceColumnTypeDetector.GetColumnName
        If offset > 3 Then
            Return String.Format("Column{0}", index)
        End If
        Dim names() As String = {"City", "Year", "Month", "Temperature"}
        Return names(index)
    End Function

    Public Function GetColumnType(ByVal index As Integer, ByVal offset As Integer, ByVal range As CellRange) As Type Implements IDataSourceColumnTypeDetector.GetColumnType
        Dim defaultType As Type = GetType(String)
        Dim value As CellValue = range(0, offset).Value
        If value.IsText Then
            Return GetType(String)
        End If
        If value.IsBoolean Then
            Return GetType(Boolean)
        End If
        If value.IsDateTime Then
            Return GetType(Date)
        End If
        If value.IsNumeric Then
            Return GetType(Double)
        End If
        Return defaultType
    End Function
End Class

See Also

IDataSourceColumnTypeDetector Members

Data Binding in WinForms Spreadsheet Control

DevExpress.Spreadsheet Namespace