[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [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
  [Collapse]Data Grid
   [Expand]Get Started With Data Grid and Views
   [Collapse]Data Binding
    [Expand]Large Data Sources: Server and Instant Feedback Modes
     Post Data to an Underlying Data Source
    Unbound Columns
   [Expand]Data Editing and Validation
   [Expand]Filter and Search
   [Expand]Focus and Selection Handling
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Batch Modifications
    Hit Information
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Sunburst 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]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com

Data Binding

Expanded Create a New Data Source

The quickest way to set up a new data source is to utilize the Data Source Configuration Wizard.

Invoke this dialog through the Data Grid smart tag or by clicking the icon in the Grid's bottom left corner.

The Wizard guides you through the binding process to the following supported sources.

The UnboundSource component allows you to mix different data source types or add virtual rows to a bound Data Grid.

For code-first data sources, it is possible to mark data class properties with Data Annotation Attributes to pre-customize a Grid (e.g., skip adding a column for a specific data field or change the type of its in-place editor).

Expanded Choose an Existing Data Source

If you already have a data source ready, use the Data Grid smart tag to select this source in the "Choose Data Source" editor.

In code, assign a valid source to the GridControl.DataSource property.

Expanded Switch to Another Data Source

Once you have chosen a data source for the first time, the Data Grid automatically generates all required columns. Should you choose another data source later, previously created columns will remain and you'll need to update them manually. To do so, launch the Data Grid Designer, switch to the "Columns" tab and click the "Retrieve Fields" button.

Expanded Post Changes to a Source

For most data source types, the Data Grid allows end-users to edit data at runtime, but these changes are not automatically saved to an underlying source. Refer to the Post Data to an Underlying Data Source article to learn how to support saving edits.

Expanded Fluent API Support

The traditional approach to customize grid columns or bind them to data assumes that you will be accessing columns using their string field names. If for any reason, it is impossible to populate grid columns at runtime or you need custom logic to obtain column settings, you can use fluent API instead. In this approach, the Visual Studio's IntelliSense allows you to observe all the data source properties and bind the required fields to grid columns.

This approach creates a fail-safe code when modifying the data source structure (e.g., removing a data source field) or a typo in a field name (attempts to access a field that does not exist) immediately causes an exception that cannot be missed. The traditional approach can ignore such errors in certain cases, creating 'dead' code that is hard to detect.

To use this functionality, refer to the XtraGrid.Extension namespace from your code.

Now, you can call the ColumnView.With method to add and configure columns. The following code snippet illustrates an example.

With fluent API, you are also able to obtain existing columns and tweak their settings. To do so, use the ColumnView.GetColumnViewSettings method. For instance, the following code is the GridView.RowCellStyle event handler that identifies the column related to the row cell and fills it in red if the column is 'Phone'.

Expanded See Also

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