All docs
21.2 (EAP/Beta)
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Lesson 2 - Display and Edit Data

  • 3 minutes to read

This tutorial demonstrates how to display and edit data within the GridControl. The tutorial is based on Lesson 1.

Create Columns

Add columns to the GridControl explicitly to access individual settings for each column.

Create the GridColumn objects and specify their ColumnBase.FieldName and ColumnBase.IsSmart properties:

<dxg:GridControl ItemsSource="{Binding Orders}">
        <dxg:TableView />
    <dxg:GridColumn FieldName="OrderId" IsSmart="True"/>
    <dxg:GridColumn FieldName="CustomerId" IsSmart="True"/>
    <dxg:GridColumn FieldName="OrderDate" IsSmart="True"/>
    <dxg:GridColumn FieldName="ShipVia" IsSmart="True"/>
    <dxg:GridColumn FieldName="Freight" IsSmart="True"/>
    <dxg:GridColumn FieldName="ShipName" IsSmart="True"/>
    <dxg:GridColumn FieldName="ShipCity" IsSmart="True"/>
    <dxg:GridColumn FieldName="ShipCountry" IsSmart="True"/>

If your field name has a complex path (like “ClientClasses.Count“) and you want the GridControl to reflect changes made in these nested properties, set the DataControlBase.DetectNestedPropertyChanges property to true.

Change Column Layout

Fit columns to the GridControl and set the optimal width for all columns to completely display their contents:

  1. Set the TableView.AutoWidth property to true to fit columns to the GridControl.
  2. Set the TableView.BestFitModeOnSourceChange to VisibleRows to calculate the optimal width for all columns:

    <dxg:GridControl ItemsSource="{Binding Orders}">
            <dxg:TableView AutoWidth="True" 

Specify an In-Place Editor

The GridControl uses in-place editors to edit cell values. The editor’s type depends on a column’s content. The CheckEdit is used for Boolean values, the DateEdit - for dates, the TextEdit - for strings and numbers. You can also define a custom editor (for example, the ComboBoxEdit):

Add a Shippers collection to the ViewModel:

using System.Collections.ObjectModel;
using Microsoft.EntityFrameworkCore;
using DevExpress.Mvvm;
using DevExpress.Mvvm.Native;
using WPFBlankDotNETCoreAppWithNorthwindDatabase.Models;

namespace WPFBlankDotNETCoreAppWithNorthwindDatabase {
    public class ViewModel : ViewModelBase {
        NorthwindEntities northwindDBContext;
        public ViewModel() {
            if (IsInDesignMode) {
                Orders = new ObservableCollection<Order>();
                Shippers = new ObservableCollection<Shipper>();
            else {
                northwindDBContext = new NorthwindEntities();

                Orders = northwindDBContext.Orders.ToObservableCollection();

                Shippers = northwindDBContext.Shippers.ToObservableCollection();
        public ObservableCollection<Order> Orders {
            get => GetValue<ObservableCollection<Order>>();
            private set => SetValue(value);
        public ObservableCollection<Shipper> Shippers {
            get => GetValue<ObservableCollection<Shipper>>();
            private set => SetValue(value);
  1. Add the xmlns:dxe="" namespace to the ThemedWindow.

  2. Create the ComboBoxEdit object and assign it to the Ship Via column’s ColumnBase.EditSettings property.

  3. Specify the ItemsSource property to bind the ComboBoxEdit to data.

  4. Set the DisplayMember property to CompanyName and the ValueMember property to ShipperId:

        <dxg:GridColumn FieldName="ShipVia" IsSmart="True">
                <dxe:ComboBoxEditSettings ItemsSource="{Binding Shippers}" 

Format Values

You can configure how the GridControl displays data. The following example formats the Freight column’s data:

  1. Create a TextEditSettings object and assign it to the Freight column’s ColumnBase.EditSettings property.

  2. Specify the TextEditSettings.MaskType and TextEditSettings.Mask properties to set the in-placed editor’s mask to Currency.

  3. Set the TextEditSettings.MaskUseAsDisplayFormat property to true:

    <dxg:GridColumn FieldName="Freight" IsSmart="True">
            <dxe:TextEditSettings Mask="c" MaskType="Numeric"            
See Also