Log In
Home
Support
Demos
Documentation
Blogs
Training
Webinars
[Expand]Welcome to DevExpress .NET Documentation
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Expand]Scheduler
  [Collapse]Spreadsheet
    Product Structure
   [Expand]Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
   [Expand]Pivot Table Overview
   [Expand]Charting Overview
    Printing
    Protection
    Find and Replace
   [Expand]Visual Elements
    Services
    Themes and Templates
   [Collapse]Examples
    [Expand]Files
    [Expand]Workbooks
    [Expand]Worksheet
    [Expand]Rows and Columns
    [Expand]Cells
    [Expand]Formulas
    [Collapse]Data Binding
      How to: Bind a Spreadsheet to an MS SQL Server Database (Part 1)
      How to: Bind a Spreadsheet to an MS SQL Server Database (Part 2)
      How to: Bind a Data Grid to a Cell Range
      How to Bind a Spreadsheet to a List of Objects
    [Expand]Formatting Cells
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Expand]Tables
    [Expand]Pivot Tables
    [Expand]Printing
    [Expand]Shapes
    [Expand]Charts
    [Expand]Protection
    [Expand]Cell Templates
    [Expand]Customization
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Diagram Control
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[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 Bind a Spreadsheet to a List of Objects

This example demonstrates how to bind a list of custom objects to a worksheet range, display and edit the object data in worksheet cells.

Expanded Custom Object

A custom object is a weather report defined as illustrated below:

Show Me

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

Expanded Data Source

A data source is a collection of the WeatherReport object and can be one of the following types:

  • System.Collections.Generic.List<T>
  • System.ComponentModel.IBindingList
  • System.Collections.ObjectModel.ReadOnlyCollection<T>

Expanded Converter

Create a MyConverter that implements the IBindingRangeValueConverter interface and converts custom objects of the Weather and List<HourlyReport> types to cell values for display. The converter is also responsible for converting cell values back to store them as custom data types.

Show Me

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

This code snippet contains the code of the converter which provides the IBindingRangeValueConverter.TryConvertFromObject method used to convert fields of a custom WeatherReport object for proper display in a worksheet and the IBindingRangeValueConverter.ConvertToObject method for storing cell values in the fields of a custom object.

Expanded Options

Create a new instance of the ExternalDataSourceOptions object. Set the ExternalDataSourceOptions.ImportHeaders option to true to show Display Name attributes as headers in the binding range. Use the DataSourceOptionsBase.CellValueConverter property to use MyConverter instead of the default converter. Specify other options if needed.

Expanded Binding

Call the WorksheetDataBindingCollection.BindToDataSource method for the specified worksheet range, with the specified options and the data source.

Show Me

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

Expanded Result

The resulting data binding range in the sample project looks as shown in the picture below:

Expanded Import Data

To import data into a worksheet, you can bind a read-only data source and subsequently remove the binding using the WorksheetDataBindingCollection.Remove or WorksheetDataBindingCollection.Clear method. Another way to import data in a worksheet is the WorksheetExtensions.Import method as described in the How to: Import Data to a Worksheet document.

Is this topic helpful?​​​​​​​