GridColumn.FieldName Property
Gets or sets the name of the data source’s field associated with the grid column, or serves as an identifier for unbound columns.
Namespace: DevExpress.XamarinForms.DataGrid
Assembly: DevExpress.XamarinForms.Grid.dll
NuGet Package: DevExpress.XamarinForms.Grid
Declaration
[XtraSerializableProperty]
public string FieldName { get; set; }
Property Value
Type | Description |
---|---|
String | The field name. |
Remarks
Use the FieldName property to associate a column with a field of the grid’s underlying data source. The grid column displays data from this field, and posts data back to this field after cell values are modified.
Unbound columns are not associated with a data source’s fields. However, these columns must also have their FieldName properties initialized. An unbound column’s field name must not match any field in the underlying data source.
You can access a column from the DataGridView.Columns collection by the field name:
<dxg:DataGridView.Columns>
<dxg:TextColumn FieldName="ProductName"/>
<dxg:NumberColumn FieldName="UnitPrice"/>
</dxg:DataGridView.Columns>
TextColumn colProduct = (TextColumn)grid.Columns["ProductName"];
NumberColumn colPrice = (NumberColumn)grid.Columns.GetColumnByFieldName("UnitPrice");
To set a caption to be displayed in a column header, use the column’s GridColumn.Caption property.
Example
This example shows how to create grid columns that display and allow users to edit data of different types (text, numbers, dates and Boolean values). The specified collection contains columns bound to the data source fields (Product.Name, Product.UnitPrice, Quantity, Date and Shipped), and one unbound column (Total) that displays data values calculated based on the values of other columns.
<dxg:DataGridView x:Name="grid" ItemsSource="{Binding Orders}" SortMode="Multiple">
<dxg:DataGridView.Columns>
<dxg:TextColumn FieldName="Product.Name" Caption = "Product" Width = "150"
SortOrder = "Descending" SortIndex = "0"/>
<dxg:NumberColumn FieldName="Product.UnitPrice" Caption = "Price" DisplayFormat="C0"/>
<dxg:NumberColumn FieldName="Quantity"
SortOrder = "Ascending" SortIndex = "1"/>
<dxg:NumberColumn FieldName="Total"
UnboundType="Integer" UnboundExpression="[Quantity] * [Product.UnitPrice]"
DisplayFormat="C0" IsReadOnly="True"/>
<dxg:DateColumn FieldName="Date" DisplayFormat="d"
IsGrouped = "true" GroupInterval = "Date"/>
<dxg:CheckBoxColumn FieldName="Shipped" AllowSort = "False"/>
</dxg:DataGridView.Columns>
</dxg:DataGridView>