Skip to main content

GridColumn.UnboundType Property

Gets or sets whether the column is unbound, and the type of data the unbound column stores.

Namespace: DevExpress.XamarinForms.DataGrid

Assembly: DevExpress.XamarinForms.Grid.dll

NuGet Package: DevExpress.XamarinForms.Grid

Declaration

[XtraSerializableProperty]
public UnboundColumnType UnboundType { get; set; }

Property Value

Type Description
UnboundColumnType

A value that specifies the data type and binding mode of the column.

Available values:

Name
Bound
Integer
Decimal
DateTime
String
Boolean
Object

Remarks

If the column’s UnboundType property is set to Bound, it’s assumed that this column stores values from a data source field that the column’s FieldName property specifies. Otherwise, the column is unbound and it displays custom values.

To create an unbound column in 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 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.

You can also use the GridColumn.IsUnbound property to obtain whether a column is unbound.

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>
    
  • Handle the DataGridView.CustomUnboundColumnData event:

    <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="Decimal"
                              IsReadOnly="True" DisplayFormat="C0"/>
        </dxg:DataGridView.Columns>
    </dxg:DataGridView>
    
    // Returns the total for a specific row.
    decimal getTotalValue(DataGridView grid, int rowHandle) {
        decimal unitPrice = Convert.ToDecimal(grid.GetCellValue(rowHandle, "Product.UnitPrice"));
        decimal quantity = Convert.ToDecimal(grid.GetCellValue(rowHandle, "Quantity"));
        return unitPrice * quantity;
    }
    
    // Provides data for the Total column.
    void Grid_CustomUnboundColumnData(object sender, GridColumnDataEventArgs e) {
        if (e.Column.FieldName == "Total" && e.IsGetData)
            e.Value = getTotalValue((DataGridView)sender, e.RowHandle);
    }
    
See Also