Back to Devexpress

GridControl.CustomUnboundColumnDataCommand Property

wpf-devexpress-dot-xpf-dot-grid-dot-gridcontrol-746dd32f.md

latest8.9 KB
Original Source

GridControl.CustomUnboundColumnDataCommand Property

Gets or sets a command that populates unbound columns with data.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public ICommand<UnboundColumnRowArgs> CustomUnboundColumnDataCommand { get; set; }
vb
Public Property CustomUnboundColumnDataCommand As ICommand(Of UnboundColumnRowArgs)

Property Value

TypeDescription
ICommand<UnboundColumnRowArgs>

A command that populates unbound columns with data.

|

Remarks

Bind a command to the CustomUnboundColumnDataCommand property to maintain a clean MVVM pattern. The command works like a CustomUnboundColumnData event handler and allows you to populate unbound columns with data in a View Model.

Unbound Columns are not bound to any field in the data source. You can calculate unbound column values based on values of bound columns or populate unbound columns with data from a custom data source.

To process unbound data in the GridControl, create a command that populates unbound columns with data and saves changes to a custom data source. Assign this command to the CustomUnboundColumnDataCommand property.

Display Unbound DataThe UnboundColumnRowArgs.IsGetData property returns true when the GridControl populates unbound columns with data. The UnboundColumnRowArgs.Item property returns the processed data source record. Specify the UnboundColumnRowArgs.Value property to display data in the unbound column.Save ChangesThe UnboundColumnRowArgs.IsSetData property returns true when a user changes a cell value. The UnboundColumnRowArgs.Value property returns the modified cell value that you can save to a custom data source.

Note

The GridControl does not execute a command bound to the CustomUnboundColumnDataCommand property if you use the TreeList View. Use the TreeListView.CustomUnboundColumnDataCommand property instead.

Example

This example shows how to add an unbound column to the GridControl. This column should display the total price, calculated as follows: UnitPrice * UnitsOnOrder.

View Example: How to Create Unbound Columns

xaml
<dxg:GridControl ItemsSource="{Binding Items}"
                 CustomUnboundColumnDataCommand="{Binding UnboundColumnDataCommand}">
    <dxg:GridColumn FieldName="CompanyName"/>
    <dxg:GridColumn FieldName="City"/>
    <dxg:GridColumn FieldName="UnitPrice">
        <dxg:GridColumn.EditSettings>
            <dxe:TextEditSettings DisplayFormat="c2"/>
        </dxg:GridColumn.EditSettings>
    </dxg:GridColumn>
    <dxg:GridColumn FieldName="Quantity"/>
    <dxg:GridColumn FieldName="Total" UnboundDataType="{x:Type sys:Decimal}" ReadOnly="True">
        <dxg:GridColumn.EditSettings>
            <dxe:TextEditSettings DisplayFormat="c2"/>
        </dxg:GridColumn.EditSettings>
    </dxg:GridColumn>
    <dxg:GridControl.View>
        <dxg:TableView AutoWidth="True"/>
    </dxg:GridControl.View>
</dxg:GridControl>
cs
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.Xpf;
// ...
public class ViewModel : ViewModelBase {
// ...
    [Command]
    public void UnboundColumnData(UnboundColumnRowArgs args) {
        if(args.IsGetData) {
            var item = (Product)args.Item;
            args.Value = item.UnitPrice * item.Quantity;
        }
    }
}
vb
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Mvvm.Xpf
' ...
Public Class ViewModel
    Inherits ViewModelBase
' ...
    <Command>
    Public Sub UnboundColumnData(ByVal args As UnboundColumnRowArgs)
        If args.IsGetData Then
            Dim item = CType(args.Item, Product)
            args.Value = item.UnitPrice * item.Quantity
        End If
    End Sub
End Class

The following code snippets (auto-collected from DevExpress Examples) contain references to the CustomUnboundColumnDataCommand property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-data-grid-create-unbound-columns/CS/DXGrid_UnboundColumns_MVVM/MainWindow.xaml#L13

xml
<dxg:GridControl ItemsSource="{Binding Items}"
                 CustomUnboundColumnDataCommand="{Binding UnboundColumnDataCommand}">
    <dxg:GridColumn FieldName="CompanyName"/>

wpf-data-grid-display-icon-in-unbound-column-based-on-value-in-bound-column/CS/UnboundColumnWithIcons_MVVM/MainWindow.xaml#L21

xml
<dxg:GridControl ItemsSource="{Binding Items}"
                 CustomUnboundColumnDataCommand="{Binding UnboundColumnDataCommand}">
    <dxg:GridControl.Columns>

wpf-bind-gridcontrol-to-dynamic-data/CS/Unbound_Columns/MainWindow.xaml#L37

xml
ColumnsSource="{Binding Columns}"
CustomUnboundColumnDataCommand="{Binding OnCustomUnboundColumnDataCommand}"
ItemsSource="{Binding Items}" />

wpf-data-grid-display-datetime-value-in-separate-date-and-time-columns/CS/DateAndTimeColumns_UnboundEditable/MainWindow.xaml#L15

xml
<Grid>
    <dxg:GridControl ItemsSource="{Binding Source}" CustomUnboundColumnDataCommand="{Binding UnboundColumnDataCommand}">
        <dxg:GridControl.Columns>

wpf-datagrid-round-decimal-values/CS/FilterDuplicateRecords_UnboundEditable/MainWindow.xaml#L16

xml
<dxg:GridControl ItemsSource="{Binding Source}"
                 CustomUnboundColumnDataCommand="{Binding UnboundColumnDataCommand}">
    <dxg:GridControl.Columns>

See Also

Unbound Columns

TreeListView.CustomUnboundColumnDataCommand

How to Display an Icon in an Unbound Column Based on the Value in a Bound Column

GridControl Class

GridControl Members

DevExpress.Xpf.Grid Namespace