GridColumn.UnboundType Property
Gets or sets whether the column is unbound, and the type of data the unbound column stores. This is a bindable property.
Namespace: DevExpress.Maui.DataGrid
Assembly: DevExpress.Maui.DataGrid.dll
NuGet Package: DevExpress.Maui.DataGrid
Declaration
public UnboundDataType UnboundType { get; set; }
Property Value
Type | Description |
---|---|
UnboundDataType | An UnboundDataType value. |
Available values:
Name | Description |
---|---|
Bound | Indicates that the column is bound to a field in the control’s underlying data source. The type of data this column contains is determined by the bound field. |
Integer | Indicates that the column is unbound and it contains integer values (the Int32 type). |
Decimal | Indicates that the column is unbound and it contains decimal values (the Decimal type). |
DateTime | Indicates that the column is unbound and it contains date/time values (the DateTime type). |
String | Indicates that the column is unbound and it contains string values (the String type). |
Boolean | Indicates that the column is unbound and it contains Boolean values (the Boolean type). |
Object | Indicates that the column is unbound and it contains values of any type. A TextEdit editor is used as an in-place editor for such a column. |
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.
- Add a column object that corresponds to the type of data the column should display to the DataGridView.Columns collection.
- 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.
- 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.
- Assign a string expression to the GridColumn.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.CustomUnboundData event to display custom values and make the unbound column editable.
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.CustomUnboundData event:
<dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}" CustomUnboundData="Grid_CustomUnboundData"> <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_CustomUnboundData(object sender, CustomUnboundDataEventArgs e) { if (e.Column.FieldName == "Total" && e.IsGetData) e.Value = getTotalValue((DataGridView)sender, e.SourceIndex); }