Skip to main content
A newer version of this page is available. .

GridColumn.UnboundExpression Property

Gets or sets an expression used to calculate values for the unbound column.

Namespace: DevExpress.XamarinForms.DataGrid

Assembly: DevExpress.XamarinForms.Grid.dll

Declaration

public string UnboundExpression { get; set; }

Property Value

Type Description
String

An expression used to calculate cell values for the current column.

Remarks

In addition to columns that obtain their data from related data source fields, DataGridView allows you to create unbound columns that are not bound to any fields of the underlying data source and display custom (calculated) data values.

To add an unbound column to the grid, do the following.

  1. Add a column object that corresponds to the type of data the column should display to the DataGridView.Columns collection.
  2. Set the column’s FieldName property to a unique string that matches neither other columns’ field names, nor any field name in the grid’s underlying data source.
  3. Specify the column’s UnboundType property according to the data type the column should display. For example, use the UnboundColumnType.Integer value if the column is supposed to display integer values.

To populate an unbound column with data, do one of the following.

  • Assign a string expression to the UnboundExpression property to calculate data values based on values of other columns. Cell values are calculated automatically, and users cannot edit them.
  • Handle the DataGridView.CustomUnboundColumnData event to display custom values and make the unbound column editable.

Example

Assume that the DataGridView instance is bound to a collection of orders. An order has the Product.Name, Product.UnitPrice and Quantity fields. This example shows how to add an unbound column (Total) to the grid to calculate each order amount according to the expression: UnitPrice*Quantity.

Implement logic to calculate column values in one of the following ways:

  • Use the GridColumn.UnboundExpression property:
<dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}">
    <dxg:DataGridView.Columns>
        <dxg:TextColumn FieldName="Product.Name" Caption="Product" Width="170" />
        <dxg:NumberColumn FieldName="Product.UnitPrice" Caption="Price" DisplayFormat="C0"/>
        <dxg:NumberColumn FieldName="Quantity"/>
        <dxg:NumberColumn FieldName="Total" UnboundType="Integer"
                          UnboundExpression="[Quantity] * [Product.UnitPrice]" 
                          IsReadOnly="True" DisplayFormat="C0"/>
    </dxg:DataGridView.Columns>
</dxg:DataGridView>
<dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}" CustomUnboundColumnData="Grid_CustomUnboundColumnData">
    <dxg:DataGridView.Columns>
        <dxg:TextColumn FieldName="Product.Name" Caption="Product" Width="170" />
        <dxg:NumberColumn FieldName="Product.UnitPrice" Caption="Price" DisplayFormat="C0"/>
        <dxg:NumberColumn FieldName="Quantity"/>
        <dxg:NumberColumn FieldName="Total" UnboundType="Integer"
                          IsReadOnly="True" DisplayFormat="C0"/>
    </dxg:DataGridView.Columns>
</dxg:DataGridView>
See Also