GridColumnDataEventArgs.Value Property
Gets or sets a value of the unbound column’s cell.
Namespace: DevExpress.XamarinForms.DataGrid
Assembly: DevExpress.XamarinForms.Grid.dll
NuGet Package: DevExpress.XamarinForms.Grid
Declaration
public object Value { get; set; }
Property Value
Type | Description |
---|---|
Object | An object that specifies the cell value. |
Remarks
If the IsGetData property is set to true (and consequently IsSetData is set to false), the DataGridView.CustomUnboundColumnData event is raised to provide data for the unbound column’s cell. Assign the required value (for example, it can be calculated based on values of other columns in the current row) to the Value property.
If the IsGetData property is set to false (and consequently IsSetData is set to true), the DataGridView.CustomUnboundColumnData event is raised to save the unbound column’s cell value after a user changed it. The Value property returns the modified cell value.
You can identify the currently processed cell by the column (Column) and row (RowHandle).
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); }